// 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, 8 Mhz internal clock, Network NODE 1 first trial #include #define rxPin 2 // Pin 2 as INPUT receives request from the Bridge board #define txPin 0 // Pin 0 as OUTPUT transmits data to the Bridge board SoftwareSerial mySerial(rxPin, txPin); // Set up Serial Port RX, TX const char node = '1'; // Network address of this NODE1 board const int ledPin = 2; // Green LED is in OUTPUT pin 2 char incomingbyte; // Variable to store the data (NODE1) void setup() { pinMode(ledPin, OUTPUT); // Green LED is OUTPUT pinMode(rxPin, INPUT); // RX is INPUT mySerial.begin(9600); // Open Serial communication between NODEs and BRIDGE (data rate 9600 bps) } void loop() { while(mySerial.available()) // Waits for node to be available and response through serial { incomingbyte = mySerial.read(); // Read the incoming byte if(incomingbyte == '1') { pinMode(txPin, OUTPUT); // Change TX as OUPUT to send a signal to the BRIDGE mySerial.print('1'); digitalWrite(ledPin, LOW); // Blink the green LED as a sign that the request is received delay(1000); digitalWrite(ledPin, HIGH); delay(500); digitalWrite(ledPin, LOW); delay(500); digitalWrite(ledPin, HIGH); delay(500); digitalWrite(ledPin, LOW); delay(200); digitalWrite(ledPin, HIGH); pinMode(txPin, INPUT); // Change TX back as INUPUT to listen a request of the BRIDGE } else { } } }