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

/media/uploads/Doye/_scaled_img_3554.jpg


Mbed pinsNokia LCD 6610
3.3Vout3.3V
GNDGND
P9RESET
P5DIO
p7SCK
P8CS
3.3VoutVBATT

Touch keypad

/media/uploads/Doye/_scaled_img_3555.jpg


Mbed pinsTouch keypad
3.3VoutVCC
GNDGND
p29IRQ
P28SDA
P27SCL

Thumb Joystick

/media/uploads/Doye/_scaled_img_3552.jpg

Mbed pinsThumb Joystick
3.3VoutVCC
VERTp16
HORIZP15
GNDGND

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

/media/uploads/Doye/_scaled_overview.jpg

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.