Created
July 22, 2013 14:44
-
-
Save silviopaganini/6054358 to your computer and use it in GitHub Desktop.
UNIT9 Interactive Fussball table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define REDPIN 5 | |
#define GREENPIN 6 | |
#define BLUEPIN 3 | |
#define GOAL_REPEAT 20 // how many times to flash when someone scores | |
#define DETECT_RIGHT A0 | |
#define DETECT_LEFT A1 | |
boolean goal; | |
int counter; | |
boolean flashing; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(REDPIN, OUTPUT); | |
pinMode(GREENPIN, OUTPUT); | |
pinMode(BLUEPIN, OUTPUT); | |
pinMode(DETECT_RIGHT, INPUT); | |
pinMode(DETECT_LEFT, INPUT); | |
goal = false; | |
counter = 0; | |
flashing = false; | |
} | |
void loop() { | |
// Serial.println(analogRead(DETECT_RIGHT)); | |
// Serial.println(analogRead(DETECT_LEFT)); | |
if(analogRead(DETECT_RIGHT) < 1023) | |
{ | |
flashGoal(true); | |
} else if(analogRead(DETECT_LEFT) < 1023) | |
{ | |
flashGoal(false); | |
} else { | |
if(flashing) return; | |
light(); | |
} | |
} | |
void flashGoal(boolean right) | |
{ | |
flashing = true; | |
for(int i = 0; i<GOAL_REPEAT; i++){ | |
delay(50); | |
analogWrite(REDPIN, right ? 255 : 0); | |
analogWrite(GREENPIN, 0); | |
analogWrite(BLUEPIN, right ? 0 : 255); | |
delay(50); | |
analogWrite(REDPIN, 0); | |
analogWrite(GREENPIN, 0); | |
analogWrite(BLUEPIN, 0); | |
} | |
flashing = false; | |
} | |
void light() | |
{ | |
analogWrite(REDPIN, 255); | |
analogWrite(GREENPIN, 255); | |
analogWrite(BLUEPIN, 255); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment