| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

CN0416_capitalizer.ino
Go to the documentation of this file.
1 /*
2 Very simple RS485 full-duplex example for CN0416.
3 Incoming characters are echoed back, with lower-case
4 characters converted to upper case. This allows the observation
5 of simultaneous traffic being transmitted and recieved, ensuring
6 that the characters are different (no cheating!)
7
8
9
10 Copyright 2018(c) Analog Devices, Inc.
11
12 All rights reserved.
13
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions are met:
16 - Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18 - Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in
20 the documentation and/or other materials provided with the
21 distribution.
22 - Neither the name of Analog Devices, Inc. nor the names of its
23 contributors may be used to endorse or promote products derived
24 from this software without specific prior written permission.
25 - The use of this software may or may not infringe the patent rights
26 of one or more patent holders. This license does not release you
27 from the requirement that you obtain separate licenses from these
28 patent holders to use this software.
29 - Use of the software either in source or binary form, must be run
30 on or directly connected to an Analog Devices Inc. component.
31
32 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
33 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
34 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
36 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
38 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
39 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
40 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
43 */
44
45
46 #include <stdint.h>
47 #include <Arduino.h>
48
49 #define DE 2 // RS485 Driver Enable pin
50
51 const uint8_t addr2ch[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; // number to character
52
53 char chaddr;
54
55 void setup() {
56 uint8_t addr = 0;
57 pinMode(DE, OUTPUT);
58 digitalWrite(DE, HIGH);
59
60 pinMode(A0, INPUT);
61 pinMode(A1, INPUT);
62 pinMode(A2, INPUT);
63 pinMode(A3, INPUT);
64
65 addr += digitalRead(A3);
66 addr << 1;
67 addr += digitalRead(A2);
68 addr << 1;
69 addr += digitalRead(A1);
70 addr << 1;
71 addr += digitalRead(A0);
72
73 if (addr > 15) {addr = 15;} // just in case...
74 chaddr = addr2ch[addr];
75 Serial.begin(9600);
76 delay(2);
77 digitalWrite(DE, HIGH);
78 Serial.print("Hello, I am node ");
79 Serial.println(chaddr);
80 Serial.flush();
81 delay(2);
82 digitalWrite(DE, LOW);
83 }
84
85
86 void loop() {
87 char ch;
88 if (Serial.available()) { // If anything comes in Serial (USB),
89 ch = Serial.read();
90 if(ch >= 'a' && ch <= 'z')
91 {
92 ch -= 32; // Convert lower-case to capital
93 }
94 Serial.write(ch); // Convert lower-case to capital
95 }
96 }
setup
static void setup()
Definition: CN0416_capitalizer.ino:55
chaddr
char chaddr
Definition: CN0416_capitalizer.ino:53
loop
static void loop()
Definition: CN0416_capitalizer.ino:86
DE
#define DE
Definition: CN0416_capitalizer.ino:49
addr2ch
const uint8_t addr2ch[16]
Definition: CN0416_capitalizer.ino:51