// Week 15 - Networking and Communications // ATtiny44A board, 20 Mhz external clock // Network node 2 // // Author: Jari Uusitalo // Modified by Kati Pitkänen on May 31, 2018 // ATtiny45 board, 16 Mhz internal clock, Network NODE 0 #include #define rxPin A1 // A1 as INPUT receives request from the Bridge board #define txPin A2 // A2 as OUTPUT transmits data to the Bridge board SoftwareSerial mySerial(rxPin, txPin); // Set up Serial Port RX, TX const char node = '0'; // Network address of this NODE0 board const int ledPin = 13; // Green LED is in OUTPUT pin 13 int incomingbyte; // Variable to store the data (NODE0) void setup() { pinMode(ledPin, OUTPUT); // Green LED is OUTPUT pinMode(rxPin, INPUT); // RX as INPUT mySerial.begin(9600); // Start Serial between NODE and Bridge (data rate to 9600 bits per second) } void loop(){ while(mySerial.available()) // Waits for node to be available and response through serial { incomingbyte = mySerial.read(); // Read the incoming byte if(incomingbyte == '0') { pinMode(txPin, OUTPUT); // Change TX as OUPUT to send a signal to the Bridge board mySerial.print("This response is sent from the node: "); mySerial.print('0'); mySerial.println("."); pinMode(txPin, INPUT); // Change TX back as INUPUT to listen and receive a request of the BRIDGE digitalWrite(ledPin, HIGH); // Blink the green LED as a sign that the request is received delay(1000); digitalWrite(ledPin, LOW); delay(500); digitalWrite(ledPin, HIGH); delay(500); digitalWrite(ledPin, LOW); delay(500); digitalWrite(ledPin, HIGH); delay(200); digitalWrite(ledPin, LOW); } else { } } }