Etch a Sketch on the uLCD screen with wheel encoders as the knobs.
Dependencies: 4DGL-uLCD-SE mbed
Diff: main.cpp
- Revision:
- 0:c1245c18d07e
- Child:
- 1:876e9cc9088b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Mar 13 21:51:12 2017 +0000 @@ -0,0 +1,86 @@ +#include "mbed.h" + +//#include "uLCD_4DGL.h" + +Serial pc(USBTX, USBRX); + +InterruptIn chA(p26); +InterruptIn chB(p25); +int chanA; +int chanB; +int currState; +int prevState; +int change; + + +//uLCD_4GDL uLCD(p9,p10,p11); +volatile int count1 = 0; +//volatile int count2 = 0; +InterruptIn pb(p21); +DigitalOut led(LED1); + + +/* +Implemented barebones version of "QEI.h" by Aaron Berk for the sake of +understanding the concept of X4 encoding +00 01 11 10 00 +4 different states +*/ + +void encode() { + change = 0; + chanA = chA.read(); + chanB = chB.read(); + currState = (chanA << 1) | (chanB); + if (((currState ^ prevState) != 0x3) && (currState != prevState)) { + // example 01 <- 11 + // change = (11&01 = 01) ^ (01&10 = 00>>1) = 1 + // example 10 -> 00 + // change = (10&01 = 00) ^ (00&10 = 00>>1) = 0 + // change = (if(left) ^ + + change = (prevState & 0x1) ^ ((currState & 0x2) >> 1); + if (change == 0) { + change = -1; + } + count1 += change; + } + prevState = currState; +} +void clear() { + //uLCD.cls(); + led = !led; +} + +int main() { + chA.mode(PullUp); + chB.mode(PullUp); + + chanA = chA.read(); + chanB = chB.read(); + currState = (chanA << 1) | (chanB); + prevState = currState; + chA.rise(&encode); + chA.fall(&encode); + chB.rise(&encode); + chB.fall(&encode); + + + pb.mode(PullUp); + pb.fall(&clear); //pb to clear screen + //add a pb to turn on and off pen + //add a pot to go through colors + //have something display current color and RGB val + while(1) { + /*if(count1 < 0) { + pc.printf("CW \n\r"); + } else { + pc.printf("CCW \n\r"); + }*/ + + pc.printf("count1: %d\r\n", count1); + pc.printf("change: %d\r\n", change); + pc.printf("---------\r\n"); + wait(.1); + } +} \ No newline at end of file