Framework for an Etch A Sketch program

Dependencies:   mbed C12832 MMA7660

Committer:
mpetovello
Date:
Fri Oct 30 04:56:59 2015 +0000
Revision:
0:a19771db916c
Child:
2:c2ebc7fa80eb
Changes for ENGO 333

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mpetovello 0:a19771db916c 1 #include "mbed.h"
mpetovello 0:a19771db916c 2 #include "MMA7660.h" // accelerometer sensor
mpetovello 0:a19771db916c 3 #include "C12832.h" // LCD display
mpetovello 0:a19771db916c 4
mpetovello 0:a19771db916c 5
mpetovello 0:a19771db916c 6 // create an accelerometer object
mpetovello 0:a19771db916c 7 MMA7660 accelerometer(p28, p27);
mpetovello 0:a19771db916c 8
mpetovello 0:a19771db916c 9 // LCD display
mpetovello 0:a19771db916c 10 C12832 lcd(p5, p7, p6, p8, p11);
mpetovello 0:a19771db916c 11
mpetovello 0:a19771db916c 12 // joystick
mpetovello 0:a19771db916c 13 BusIn joystick(p15,p12,p13,p16);
mpetovello 0:a19771db916c 14
mpetovello 0:a19771db916c 15 // LEDs
mpetovello 0:a19771db916c 16 BusOut LEDs(LED1,LED2,LED3,LED4);
mpetovello 0:a19771db916c 17
mpetovello 0:a19771db916c 18 int main()
mpetovello 0:a19771db916c 19 {
mpetovello 0:a19771db916c 20 // try to establish a connection with the accelerometer
mpetovello 0:a19771db916c 21 if( !accelerometer.testConnection() )
mpetovello 0:a19771db916c 22 {
mpetovello 0:a19771db916c 23 // turn on all LEDs (indicating an error state)
mpetovello 0:a19771db916c 24 LEDs = 0xf;
mpetovello 0:a19771db916c 25 return 0;
mpetovello 0:a19771db916c 26 }
mpetovello 0:a19771db916c 27
mpetovello 0:a19771db916c 28 // clear the LCD
mpetovello 0:a19771db916c 29 lcd.cls();
mpetovello 0:a19771db916c 30
mpetovello 0:a19771db916c 31
mpetovello 0:a19771db916c 32 // TODO: Move to the centre of the LCD and set the corresponding pixel to black
mpetovello 0:a19771db916c 33 // We will call the current location the "active pixel"
mpetovello 0:a19771db916c 34
mpetovello 0:a19771db916c 35
mpetovello 0:a19771db916c 36 // create an infinite loop (i.e., the program runs as long as the processor is on)
mpetovello 0:a19771db916c 37 while(1)
mpetovello 0:a19771db916c 38 {
mpetovello 0:a19771db916c 39 // TODO: Get the state/value of the joystick
mpetovello 0:a19771db916c 40
mpetovello 0:a19771db916c 41
mpetovello 0:a19771db916c 42 // TODO: Determine the coordinates of the next active pixel based on joystick data
mpetovello 0:a19771db916c 43
mpetovello 0:a19771db916c 44
mpetovello 0:a19771db916c 45 // TODO: Set the next pixel to black
mpetovello 0:a19771db916c 46
mpetovello 0:a19771db916c 47
mpetovello 0:a19771db916c 48 // TODO: Get the accelerometer measurements
mpetovello 0:a19771db916c 49
mpetovello 0:a19771db916c 50
mpetovello 0:a19771db916c 51 // TODO: Check if the screen should be cleared based on the accelerometer
mpetovello 0:a19771db916c 52 // measurements, and if so, clear the screen but don't move the active
mpetovello 0:a19771db916c 53 // pixel.
mpetovello 0:a19771db916c 54 //
mpetovello 0:a19771db916c 55 // NOTE: Although you may have an idea of how to do this, it may take some
mpetovello 0:a19771db916c 56 // "tuning" to get it to "feel right".
mpetovello 0:a19771db916c 57
mpetovello 0:a19771db916c 58
mpetovello 0:a19771db916c 59
mpetovello 0:a19771db916c 60 // wait a short period
mpetovello 0:a19771db916c 61 wait(0.1);
mpetovello 0:a19771db916c 62 }
mpetovello 0:a19771db916c 63
mpetovello 0:a19771db916c 64 // end of program
mpetovello 0:a19771db916c 65 return 0;
mpetovello 0:a19771db916c 66 }