#include #include #include #include #define RS 11 #define EN 10 #define D4 6 #define D5 5 #define D6 4 #define D7 1 #define led1 26 #define led2 27 #define led3 28 #define led4 29 #define buzz 0 #define d1 25 #define d2 24 #define d3 23 #define d4 22 int flag1=0,flag2=0,flag3=0,flag4=0; void lcdcmd(unsigned int ch) { int temp=0x80; digitalWrite(D4, temp & ch<<3); digitalWrite(D5, temp & ch<<2); digitalWrite(D6, temp & ch<<1); digitalWrite(D7, temp & ch); digitalWrite(RS, LOW); digitalWrite(EN, HIGH); delay(10); digitalWrite(EN, LOW); digitalWrite(D4, temp & ch<<7); digitalWrite(D5, temp & ch<<6); digitalWrite(D6, temp & ch<<5); digitalWrite(D7, temp & ch<<4); digitalWrite(RS, LOW); digitalWrite(EN, HIGH); delay(10); digitalWrite(EN, LOW); } void write(unsigned int ch) { int temp=0x80; digitalWrite(D4, temp & ch<<3); digitalWrite(D5, temp & ch<<2); digitalWrite(D6, temp & ch<<1); digitalWrite(D7, temp & ch); digitalWrite(RS, HIGH); digitalWrite(EN, HIGH); delay(10); digitalWrite(EN, LOW); digitalWrite(D4, temp & ch<<7); digitalWrite(D5, temp & ch<<6); digitalWrite(D6, temp & ch<<5); digitalWrite(D7, temp & ch<<4); digitalWrite(RS, HIGH); digitalWrite(EN, HIGH); delay(10); digitalWrite(EN, LOW); } void clear() { lcdcmd(0x01); } void setCursor(int x, int y) { int set=0; if(y==0) set=128+x; if(y==1) set=192+x; lcdcmd(set); } void print(char *str) { while(*str) { write(*str); str++; } } void begin(int x, int y) { lcdcmd(0x02); lcdcmd(0x28); lcdcmd(0x06); lcdcmd(0x0e); lcdcmd(0x01); } void buzzer() { digitalWrite(buzz, HIGH); delay(1000); digitalWrite(buzz, LOW); } void setup() { if (wiringPiSetup () == -1) { clear(); print("Unable to start"); setCursor(0,1); print("wiringPi"); } pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(buzz, OUTPUT); pinMode(RS, OUTPUT); pinMode(EN, OUTPUT); pinMode(D4, OUTPUT); pinMode(D5, OUTPUT); pinMode(D6, OUTPUT); pinMode(D7, OUTPUT); pinMode(d1, INPUT); pinMode(d2, INPUT); pinMode(d3, INPUT); pinMode(d4, INPUT); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); digitalWrite(buzz, LOW); begin(16,2); } //void loop() void main() { setup(); clear(); print(" RF Module "); setCursor(0,1); print(" Interfacing "); delay(2000); clear(); print("Raspberry Pi"); setCursor(0,1); print("Circuit Digest"); delay(2000); clear(); print("System Ready"); delay(1000); clear(); setCursor(0,1); print("OFF OFF OFF OFF"); while(1) { setCursor(0,0); print("D1 D2 D3 D4"); if(digitalRead(d1)==0) { flag1++; setCursor(0,1); if(flag1%2==1) { print("ON "); digitalWrite(led1,HIGH); } else { print("OFF"); digitalWrite(led1,LOW); } buzzer(); while(digitalRead(d1)==0); } else if(digitalRead(d2)==0) { flag2++; setCursor(4,1); if(flag2%2==1) { print("ON "); digitalWrite(led2,HIGH); } else { print("OFF"); digitalWrite(led2,LOW); } buzzer(); while(digitalRead(d2)==0); } else if(digitalRead(d3)==0) { flag3++; setCursor(8,1); if(flag3%2==1) { print("ON "); digitalWrite(led3,HIGH); } else { print("OFF"); digitalWrite(led3,LOW); } buzzer(); while(digitalRead(d3)==0); } else if(digitalRead(d4)==0) { flag4++; setCursor(12,1); if(flag4%2==1) { print("ON "); digitalWrite(led4,HIGH); } else { print("OFF"); digitalWrite(led4,LOW); } buzzer(); while(digitalRead(d4)==0); } } }