Here is the code. All system is working but i only need one help from pros, i also use ethernet shield over uno r3 and i want to add sdcard abilities to this code.
I have to count press amounts to each button and then write it to sdcard with 3 different file, like spray.txt,red.txt and green.txt
When system starts ws2801 has to show the avarage vote color ,also it has to show avarage color after 10 seconds of each voting.Somehow i have to record press amounts then make percent calculation with them and add if statement like “if green buton percent higher than red button light up ws2801 with green color” If someone can help i will be glad for that.
//SMELL VOTER- by Burak TURCAN
#include<FTRGBLED.h>
#include<SPI.h>
#define Pbuton 5 // spray button
#define Kbuton 6 // red vote button
#define Ybuton 7 // green vote button
#define YKLed 8 // red and green button led (will be in blink mode until vote button pressed. After 15 sec. go LOW
#define PIN_CKI 2 // WS2801 connection pins
#define PIN_SDI 3 // WS2801 connection pins
#define PLed A0 // spray button yelow led
#define roLeP 11// spray button relay
#define roLeK 12// red button relay
#define roLeY 13//green button relay
#define kokuM 9//spray triger which connecting to smell emitter device
int pbtn=0;
int kbtn=0;
int ybtn=0;
const int NUM_LEDS = 10;
RGBLEDChain leds(NUM_LEDS,PIN_CKI,PIN_SDI);
int x=0;
int y=0;
int z=0;
int a=0;
int b=0;
int c=0;
void setup()
{
Serial.begin(9600);
leds.begin();
pinMode(Pbuton, INPUT);//spray relay
pinMode(Kbuton, INPUT);//red button relay
pinMode(Ybuton, INPUT);//green button relay
pinMode(YKLed, OUTPUT);//green and red blinking leds
pinMode(PLed, OUTPUT);//spray button yellow led
pinMode(kokuM, OUTPUT);//sray triger
pinMode(roLeP, OUTPUT);//spray button
pinMode(roLeK, OUTPUT);//red button
pinMode(roLeY, OUTPUT);//green button
}
void loop()
{
kbtn =digitalRead(Kbuton);
ybtn =digitalRead(Ybuton);
pbtn =digitalRead(Pbuton);
digitalWrite(PLed, HIGH);
digitalWrite(YKLed, LOW);
digitalWrite(kokuM, LOW);
digitalWrite(roLeP, LOW);//spray button relay is activated
digitalWrite(roLeK, HIGH);//red button relay is passive
digitalWrite(roLeY, HIGH);//green button relay passive
leds.setLED(0, { 0, 0, 0 });//WS2801 LED0 off
leds.setLED(1, { 0, 0, 0 });//WS2801 LED1 off
leds.setLED(2, { 0, 0, 0 });//WS2801 LED2 off
leds.setLED(3, { 0, 0, 0 });//WS2801 LED3 off
leds.setLED(4, { 0, 0, 0 });//WS2801 LED4 off
leds.setLED(5, { 0, 0, 0 });//WS2801 LED5 off
leds.setLED(6, { 0, 0, 0 });//WS2801 LED6 off
leds.setLED(7, { 0, 0, 0 });//WS2801 LED7 off
leds.setLED(8, { 0, 0, 0 });//WS2801 LED8 off
leds.setLED(9, { 0, 0, 0 });//WS2801 LED9 off
leds.update();
switch(pbtn)
{
case HIGH:
digitalWrite(roLeP, HIGH);
digitalWrite(PLed, LOW);
digitalWrite(kokuM, HIGH);
delay(1000);
digitalWrite(kokuM, LOW);
for(x=0;x<75;x++)
{
digitalWrite(YKLed, HIGH);
oy();
delay(100);
digitalWrite(YKLed, LOW);
oy();
delay(100);
digitalWrite(roLeK, LOW);
digitalWrite(roLeY, LOW);
}
break;
case LOW:
digitalWrite(YKLed, LOW);
digitalWrite(kokuM, LOW);
digitalWrite(PLed, LOW);
digitalWrite(roLeP, LOW);
digitalWrite(roLeK, HIGH);
digitalWrite(roLeY, HIGH);
leds.setLED(0, { 0, 0, 0 });//WS2801 LED0 off
leds.setLED(1, { 0, 0, 0 });//WS2801 LED1 off
leds.setLED(2, { 0, 0, 0 });//WS2801 LED2 off
leds.setLED(3, { 0, 0, 0 });//WS2801 LED3 off
leds.setLED(4, { 0, 0, 0 });//WS2801 LED4 off
leds.setLED(5, { 0, 0, 0 });//WS2801 LED5 off
leds.setLED(6, { 0, 0, 0 });//WS2801 LED6 off
leds.setLED(7, { 0, 0, 0 });//WS2801 LED7 off
leds.setLED(8, { 0, 0, 0 });//WS2801 LED8 off
leds.setLED(9, { 0, 0, 0 });//WS2801 LED9 off
leds.update();
break;
}
}
void oy()
{
kbtn =digitalRead(Kbuton);
ybtn =digitalRead(Ybuton);
if(kbtn==HIGH)
{
if(ybtn==HIGH)
{
for(int f=0;f<2;f++)
{
bosluk();
}
}
}
switch(kbtn)
{
case HIGH:
x=75;
digitalWrite(roLeY, HIGH);
digitalWrite(roLeK, HIGH);
digitalWrite(YKLed, LOW);
digitalWrite(PLed, LOW);
digitalWrite(kokuM, LOW);
digitalWrite(roLeP, HIGH);
for(y=0;y<255;y++)
{
leds.setLED(0, { 0, 0, y });
leds.setLED(1, { 0, 0, y });
leds.setLED(2, { 0, 0, y });
leds.setLED(3, { 0, 0, y });
leds.setLED(4, { 0, 0, y });
leds.setLED(5, { 0, 0, y });
leds.setLED(6, { 0, 0, y });
leds.setLED(7, { 0, 0, y });
leds.setLED(8, { 0, 0, y });
leds.setLED(9, { 0, 0, y });
leds.update();
delay(20);
}
for(a=255;a>0;a--)
{
leds.setLED(0, { 0, 0, a });
leds.setLED(1, { 0, 0, a });
leds.setLED(2, { 0, 0, a });
leds.setLED(3, { 0, 0, a });
leds.setLED(4, { 0, 0, a });
leds.setLED(5, { 0, 0, a });
leds.setLED(6, { 0, 0, a });
leds.setLED(7, { 0, 0, a });
leds.setLED(8, { 0, 0, a });
leds.setLED(9, { 0, 0, a });
leds.update();
delay(20);
}
break;
}
switch(ybtn)
{
case HIGH:
x=75;
digitalWrite(roLeK, HIGH);
digitalWrite(roLeY, HIGH);
digitalWrite(YKLed, LOW);
digitalWrite(PLed, LOW);
digitalWrite(kokuM, LOW);
digitalWrite(roLeP, HIGH);
for(z=0;z<255;z++)
{
leds.setLED(0, { 0, z, 0 });
leds.setLED(1, { 0, z, 0 });
leds.setLED(2, { 0, z, 0 });
leds.setLED(3, { 0, z, 0 });
leds.setLED(4, { 0, z, 0 });
leds.setLED(5, { 0, z, 0 });
leds.setLED(6, { 0, z, 0 });
leds.setLED(7, { 0, z, 0 });
leds.setLED(8, { 0, z, 0 });
leds.setLED(9, { 0, z, 0 });
leds.update();
delay(20);
}
for(b=255;b>0;b--)
{
leds.setLED(0, { 0, b, 0 });
leds.setLED(1, { 0, b, 0 });
leds.setLED(2, { 0, b, 0 });
leds.setLED(3, { 0, b, 0 });
leds.setLED(4, { 0, b, 0 });
leds.setLED(5, { 0, b, 0 });
leds.setLED(6, { 0, b, 0 });
leds.setLED(7, { 0, b, 0 });
leds.setLED(8, { 0, b, 0 });
leds.setLED(9, { 0, b, 0 });
leds.update();
delay(20);
}
break;
}
}
void bosluk()
{
digitalWrite(roLeY, HIGH);
digitalWrite(roLeK, HIGH);
digitalWrite(roLeP, HIGH);
digitalWrite(PLed, LOW);
leds.setLED(0, { 0, 0, 0 });//WS2801 LED0 off
leds.setLED(1, { 0, 0, 0 });//WS2801 LED1 off
leds.setLED(2, { 0, 0, 0 });//WS2801 LED2 off
leds.setLED(3, { 0, 0, 0 });//WS2801 LED3 off
leds.setLED(4, { 0, 0, 0 });//WS2801 LED4 off
leds.setLED(5, { 0, 0, 0 });//WS2801 LED5 off
leds.setLED(6, { 0, 0, 0 });//WS2801 LED6 off
leds.setLED(7, { 0, 0, 0 });//WS2801 LED7 off
leds.setLED(8, { 0, 0, 0 });//WS2801 LED8 off
leds.setLED(9, { 0, 0, 0 });//WS2801 LED9 off
leds.update();
digitalWrite(PLed, LOW);
digitalWrite(YKLed, LOW);
digitalWrite(kokuM, LOW);
x=75;
delay(1000);
oy();
}