| 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 = 14; |
| 8 | char offset = 8; |
| 9 | float val = 0, oldval = -255; |
| 10 | |
| 11 | void setup() // run once, when the sketch starts |
| 12 | { |
| 13 | stadium_max+=offset; |
| 14 | Serial.begin(115200); |
| 15 | } |
| 16 | |
| 17 | void loop() // run over and over again |
| 18 | { |
| 19 | val = analogRead(inpin); |
| 20 | if(val<min) min=val; |
| 21 | if(val>max) max=val; |
| 22 | val=(((val-(min))/(max-(min)))*stadium_max)-offset; |
| 23 | if(val!=oldval) { |
| 24 | oldval = val; |
| 25 | //Serial.print(min, DEC); Serial.print("-"); Serial.print(max, DEC); Serial.print("\n"); |
| 26 | //Serial.print(val, DEC); Serial.print("\n"); |
| 27 | Serial.print(val, BYTE); |
| 28 | } |
| 29 | delay(1); |
| 30 | } |