Nokia LCD etch-A-sketch
General Description
The Etch-A-Sketch uses an analog Sparkfun thumb joystick to draw on a Nokia 6610 128x128 LCD screen. A 12-key capacitive touchpad is used to access different features, such as changing colors, clearing the screen, and drawing thicker lines.
Wire Connections
Nokia LCD
Mbed pins | Nokia LCD 6610 |
---|---|
3.3Vout | 3.3V |
GND | GND |
P9 | RESET |
P5 | DIO |
p7 | SCK |
P8 | CS |
3.3Vout | VBATT |
Touch keypad
Mbed pins | Touch keypad |
---|---|
3.3Vout | VCC |
GND | GND |
p29 | IRQ |
P28 | SDA |
P27 | SCL |
Thumb Joystick
Mbed pins | Thumb Joystick |
---|---|
3.3Vout | VCC |
VERT | p16 |
HORIZ | P15 |
GND | GND |
Problems Encountered
Attempted to use an Accelerometer but the output was extremely noisy
and required filtering. Decided to use a thumb joystick which
was more precise than the accelerometer and did not require filtering.
Setup
Video Demo
Code
#include "mbed.h" #include "time.h" #include "NokiaLCD.h" #include "Joystick.h" #include "mpr121.h" NokiaLCD lcd(p5, p7, p8, p9, NokiaLCD::LCD6610); // mosi, sclk, cs, rst, type Serial pc(USBTX, USBRX); DigitalIn pb(p20); DigitalOut led(LED1); DigitalOut led2(LED2); Joystick Dir(p17,p15,p16); I2C i2c(p28, p27); InterruptIn interrupt(p29); Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); int key = 0; // Key hit/release interrupt routine // Warning: Keep code in interrupt to a minimum to prevent crash void fallInterrupt() { int key_code = 0; int i=0; int value = mpr121.read(0x00); value += mpr121.read(0x01)<<8; // LED demo mod // puts key number out to LEDs for demo // scans mpr121 register bits in order to determine which key was pressed for (i=0; i<12; i++) { if (((value>>i)&0x01)==1) { key_code = i; } } key = key_code; } int main() { interrupt.fall(&fallInterrupt); interrupt.mode(PullUp); //Set up NokiaLCD int back = 0xFFFFFF; lcd.background(back); lcd.cls(); srand(time(0)); int x = 0; int y = 0; int color = 0xFFFFFF; double XReading; double YReading; int directionX; int directionY; int cursorX = 64; int cursorY = 64; int toggle = 0; while(1) { x = 10 + rand()% 118; y = 10 + rand()% 118; XReading = Dir.getH(); YReading = Dir.getV(); directionX = (XReading*10)-5; directionY = (YReading*10)-5; pc.printf("%i, %i\r\n", directionX, directionY); //Touch pad key functionality if(key == 4) { color = 0x00000F + rand() % 0xFFFFF0; } else if(key == 5) { wait(0.1); lcd.fill(x,y,10,10,color); wait(0.1); } else if(key == 6){ lcd.cls(); } else if(key == 7){ cursorX = x; cursorY = y; } else if (key ==8) { if (toggle == 0) { toggle = 1; } else if (toggle == 1) { toggle = 0; } } //Thumb Joystick functionality //Draw for X if(directionX == 0) { led2 = 1; } else if(directionX > 0) { led2 = 0; lcd.pixel(cursorX++,cursorY,color); if(toggle) lcd.pixel(cursorX,cursorY+1,color); lcd.pixel(cursorX,cursorY-1,color); } else if(directionX < 0) { led2 = 0; lcd.pixel(cursorX--,cursorY,color); if(toggle) lcd.pixel(cursorX,cursorY-1,color); lcd.pixel(cursorX,cursorY+1,color); } //Draw for Y if(directionY == 0) { led2 = 1; } else if(directionY > 0) { led2 = 0; lcd.pixel(cursorX,cursorY++,color); if(toggle) lcd.pixel(cursorX+1,cursorY,color); lcd.pixel(cursorX-1,cursorY,color); } else if(directionY < 0) { led2 = 0; lcd.pixel(cursorX,cursorY--,color); if(toggle) lcd.pixel(cursorX-1,cursorY,color); lcd.pixel(cursorX+1,cursorY,color); } //Boundary check if(cursorX > 123) cursorX = 123; if(cursorX < 2) cursorX = 2; if(cursorY > 123) cursorY = 123; if(cursorY < 2) cursorY = 2; } }
Please log in to post comments.