00001 #include "DemoBoard.h"00002
00003 /*00004 * This project uses the LCD, the two pots, and the three buttons to make a simple00005 * Etch-a-Sketch. Set the colour using the buttons, and use the pots to draw!00006 * Oh yeah, more than 1.5 in any axis will clear the screen :-)00007 */00008
00009 int colour = 0x0;
00010
00011 // Functions to set the draw colour. Write this to the RGB LED00012 void RedRise() { colour = 0xff0000; rgb.write(colour);}
00013 void GreenRise() { colour = 0x00ff00; rgb.write(colour);}
00014 void BlueRise() { colour = 0x0000ff; rgb.write(colour);}
00015
00016 int main() {
00017
00018
00019 // Attach the colour set functions to00020 // rising edge interrupt handlers00021 RedButton.rise(&RedRise);
00022 GreenButton.rise(&GreenRise);
00023 BlueButton.rise(&BlueRise);
00024
00025 // set the screen background to white00026 lcd.fill(0,0,130,130,0xffffff);
00027
00028 while(1) {
00029 // fetch the values from the pots, and scale them to 0-13000030 int x = potx * 130;
00031 int y = poty * 130;
00032
00033 // draw the pixel!00034 lcd.pixel(x,y,colour);
00035 wait(0.01);
00036
00037 // If any axis of the accelerometer read > 1.5g, clear the screen00038 if ( (acc.x() > 1.5) || (acc.y() > 1.5) || (acc.x() > 1.5) ) {
00039 lcd.cls();
00040 lcd.fill(0,0,130,130,0xffffff);
00041 }
00042
00043 }
00044
00045 }
00046
00047