Chris Styles
/
DemoBoard_EtchASketch
main.cpp@2:0bfbaf4f4281, 2009-09-22 (annotated)
- Committer:
- chris
- Date:
- Tue Sep 22 12:12:01 2009 +0000
- Revision:
- 2:0bfbaf4f4281
- Parent:
- 1:95cd28d01d06
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 2:0bfbaf4f4281 | 1 | #include "DemoBoard.h" |
chris | 0:159c4d4552b7 | 2 | |
chris | 0:159c4d4552b7 | 3 | /* |
chris | 0:159c4d4552b7 | 4 | * This project uses the LCD, the two pots, and the three buttons to make a simple |
chris | 0:159c4d4552b7 | 5 | * Etch-a-Sketch. Set the colour using the buttons, and use the pots to draw! |
chris | 0:159c4d4552b7 | 6 | * Oh yeah, more than 1.5 in any axis will clear the screen :-) |
chris | 0:159c4d4552b7 | 7 | */ |
chris | 0:159c4d4552b7 | 8 | |
chris | 0:159c4d4552b7 | 9 | int colour = 0x0; |
chris | 0:159c4d4552b7 | 10 | |
chris | 1:95cd28d01d06 | 11 | // Functions to set the draw colour. Write this to the RGB LED |
chris | 1:95cd28d01d06 | 12 | void RedRise() { colour = 0xff0000; rgb.write(colour);} |
chris | 1:95cd28d01d06 | 13 | void GreenRise() { colour = 0x00ff00; rgb.write(colour);} |
chris | 1:95cd28d01d06 | 14 | void BlueRise() { colour = 0x0000ff; rgb.write(colour);} |
chris | 0:159c4d4552b7 | 15 | |
chris | 0:159c4d4552b7 | 16 | int main() { |
chris | 0:159c4d4552b7 | 17 | |
chris | 0:159c4d4552b7 | 18 | |
chris | 0:159c4d4552b7 | 19 | // Attach the colour set functions to |
chris | 0:159c4d4552b7 | 20 | // rising edge interrupt handlers |
chris | 0:159c4d4552b7 | 21 | RedButton.rise(&RedRise); |
chris | 0:159c4d4552b7 | 22 | GreenButton.rise(&GreenRise); |
chris | 0:159c4d4552b7 | 23 | BlueButton.rise(&BlueRise); |
chris | 0:159c4d4552b7 | 24 | |
chris | 0:159c4d4552b7 | 25 | // set the screen background to white |
chris | 0:159c4d4552b7 | 26 | lcd.fill(0,0,130,130,0xffffff); |
chris | 0:159c4d4552b7 | 27 | |
chris | 0:159c4d4552b7 | 28 | while(1) { |
chris | 0:159c4d4552b7 | 29 | // fetch the values from the pots, and scale them to 0-130 |
chris | 0:159c4d4552b7 | 30 | int x = potx * 130; |
chris | 0:159c4d4552b7 | 31 | int y = poty * 130; |
chris | 0:159c4d4552b7 | 32 | |
chris | 0:159c4d4552b7 | 33 | // draw the pixel! |
chris | 0:159c4d4552b7 | 34 | lcd.pixel(x,y,colour); |
chris | 0:159c4d4552b7 | 35 | wait(0.01); |
chris | 0:159c4d4552b7 | 36 | |
chris | 0:159c4d4552b7 | 37 | // If any axis of the accelerometer read > 1.5g, clear the screen |
chris | 0:159c4d4552b7 | 38 | if ( (acc.x() > 1.5) || (acc.y() > 1.5) || (acc.x() > 1.5) ) { |
chris | 0:159c4d4552b7 | 39 | lcd.cls(); |
chris | 0:159c4d4552b7 | 40 | lcd.fill(0,0,130,130,0xffffff); |
chris | 0:159c4d4552b7 | 41 | } |
chris | 0:159c4d4552b7 | 42 | |
chris | 0:159c4d4552b7 | 43 | } |
chris | 0:159c4d4552b7 | 44 | |
chris | 0:159c4d4552b7 | 45 | } |
chris | 0:159c4d4552b7 | 46 | |
chris | 0:159c4d4552b7 | 47 |