| 1 | /* Pong controller (for use with hPong) |
| 2 | * <~~Harvie 2oo8 |
| 3 | */ |
| 4 | |
| 5 | #define inpin 0 |
| 6 | int min = 65535, max = 0; |
| 7 | int stadium_max = 70; |
| 8 | char offset = 0; |
| 9 | float val = 0, oldval = -255; |
| 10 | int sndPin = 12; |
| 11 | |
| 12 | void setup() // run once, when the sketch starts |
| 13 | { |
| 14 | stadium_max+=offset; |
| 15 | Serial.begin(19200); |
| 16 | pinMode(sndPin, OUTPUT); |
| 17 | } |
| 18 | |
| 19 | void loop() // run over and over again |
| 20 | { |
| 21 | val = analogRead(inpin); |
| 22 | if(val<min) min=val; |
| 23 | if(val>max) max=val; |
| 24 | val=(((val-(min))/(max-(min)))*stadium_max)-offset; |
| 25 | /*if(val!=oldval) { |
| 26 | oldval = val; |
| 27 | //Serial.print(min, DEC); Serial.print("-"); Serial.print(max, DEC); Serial.print("\n"); |
| 28 | //Serial.print(val, DEC); Serial.print("\n"); |
| 29 | //Serial.print(val, BYTE); |
| 30 | }*/ |
| 31 | val=val; |
| 32 | digitalWrite(sndPin, HIGH); |
| 33 | delay(val); |
| 34 | digitalWrite(sndPin, LOW); |
| 35 | delay(val); |
| 36 | } |