Networking & Communications | Week 15
Controlling RGB of Main board from LED Board via Switch
In this week I have used two boards
- My Final Project Board using 328P
- LED and Switch board using Atty Tiny
- I have added two external LED to my Final Project Board to check Networking and communication.
This week I have worked with two circuit board each of them is communicating with rx tx pins
one board is multiple LED and other board is My Master bored with a design for my final project Makerbot.
from Masters circuit sends a signal is slave Circuit to start a LED.
My Slave Circuit decide a Delay and start LED.
After delay my Slave Circuit send a signal to Master Circuit. That LED is off then only we can start other LED.
I have added both Code with comments to understand the same process.
Code for Slave Circuit
#include <SoftwareSerial.h>
SoftwareSerial myS(6,5); // rx, tx
int r = 11;
int b = 12;
int R_INT;
char c;
void setup()
{
myS.begin(9600);
Serial.begin(9600);
pinMode(r, OUTPUT);
pinMode(b, OUTPUT);
}
void loop()
{
if( myS.available() ){
R_INT = random(20, 80) * 100;
c = myS.read();
Serial.println(R_INT);
if( c == 'r' ){
digitalWrite(r, HIGH);
digitalWrite(b, LOW);
delay(R_INT);
myS.write('o');
digitalWrite(r, LOW);
}
else if( c == 'b') {
digitalWrite(r, LOW);
digitalWrite(b, HIGH);
delay(R_INT);
myS.write('k');
digitalWrite(b, LOW);
}
}
}
Code for second circuit Maker Bot ( Master )
#include <SoftwareSerial.h>
SoftwareSerial mySerial(5,6);//Rx,Tx
char c;
void BlinkOne(){
//turn on LED
digitalWrite(0,HIGH);
digitalWrite(1,LOW);
delay(300);
//turn off led immidiately
digitalWrite(0,LOW);
}
void BlinkTwo(){
//turn on second LED
digitalWrite(1,HIGH);
digitalWrite(0,LOW);
delay(300);
//turn off led immidiately
digitalWrite(1,LOW);
}
void waitAck(){
while( ! mySerial.available() );
c = mySerial.read();
if( c == 'o'){
//Acknowledgment recieved that LED1 of slave turned off after some random time
BlinkOne();
}
else if( c == 'k'){
//Acknowledgment recieved that LED2 of slave turned off after some random time
BlinkTwo();
}
}
void setup() {
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
mySerial.begin(9600);
}
void loop() {
if( digitalRead(9) == LOW){
//tell slave board to turn on 'r' light
mySerial.write('r');
//Blink LED1 to indicate Data sent
BlinkOne();
waitAck();
}
else if( digitalRead(8) == LOW){
//tell slave board to turn on 'b' light
mySerial.write('b');
//Blink LED2 to indicate Data sent
BlinkTwo();
waitAck();
}
}
LED control with other Circuits by Rx & Tx
Files
- Maker Bot Schematic file | .sch | Eagle
- Maker Bot Board file | .brd | Eagle
- LED Counter SCH
- LED Counter BRD
- RGB Blue-tooth Code | .ino | Arduino
- LED Circuit Networking Code | .ino | Arduino