miniBLIP - paint on matrix

Dependencies:   USBDevice mbed

Fork of blip_dado by Alberto Piganti

Files at this revision

API Documentation at this revision

Comitter:
pighixxx
Date:
Mon Jan 18 09:02:05 2016 +0000
Parent:
7:5b8708227c46
Commit message:
1st revision

Changed in this revision

PixelArray.lib Show diff for this revision Revisions of this file
USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 5b8708227c46 -r ab4a9bc09839 PixelArray.lib
--- a/PixelArray.lib	Wed Dec 02 13:47:34 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/JacobBramley/code/PixelArray/#47802e75974e
diff -r 5b8708227c46 -r ab4a9bc09839 USBDevice.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Mon Jan 18 09:02:05 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#0e6b3f44926e
diff -r 5b8708227c46 -r ab4a9bc09839 main.cpp
--- a/main.cpp	Wed Dec 02 13:47:34 2015 +0000
+++ b/main.cpp	Mon Jan 18 09:02:05 2016 +0000
@@ -1,9 +1,7 @@
-// miniblip sketch demo
 
 #include "mbed.h"
-#include "neopixel.h"
+#include "USBKeyboard.h"  
 
-// Matrix led output pin
 #define DATA_PIN P0_9
 #define TOUCH_N     2
 #define ANALOG_PHOTO P0_16
@@ -18,70 +16,11 @@
 AnalogIn   ain(ANALOG_POTENTIOMETER);
 Ticker tick;
 
-void fill_pixel(neopixel::Pixel buffer[25], int x, int y, int red, int green, int blue){
-    
-    if(x<0) x=0;
-    if(x>4) x=4;
-    if(y<0) y=0;
-    if(y>4) y=4;
-       
-
-    int posicion=x+y*5;
-    buffer[posicion].red=red;
-    buffer[posicion].green=green;
-    buffer[posicion].blue=blue;
-}
-
-void void_matrix(neopixel::Pixel aux[25], int tam=25){
-    
-    for(int i=0;i<tam;i++){
-        aux[i].red=0;
-        aux[i].green=0;
-        aux[i].blue=0;
-    }
-}
-
-int pant[5][5] = {
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0}
-};
+uint8_t       key_map[] = {'1', '2', '3', '4', '5', '6', '7', '8', '8','\n'};
+uint16_t touch_data[TOUCH_N] = {0, };
 
-int pantR[5][5] = {
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0}
-};
-
-int pantG[5][5] = {
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0}
-};
-
-int pantB[5][5] = {
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0},
-{0,0,0,0,0}
-};
-
-int palR[15] = { 5,10,15, 0,30,30, 0, 0, 0, 5,10,30,10,10,10};
-int palG[15] = { 0,10, 0,30,30, 5,10,15,20,20, 0,30, 0, 0, 0};
-int palB[15] = { 0, 0,10, 0, 0, 0, 0,15,20,10,10,30,20,10,30};
-int actualR=30; 
-int actualG=0;
-int actualB=0;
-
-uint16_t touch_data[TOUCH_N] = {0, };
-int modo=10;
+// Virtual serial port over USB
+USBKeyboard keyboard;
 
 // Pushbutton
 DigitalIn pushbutton(P0_23);
@@ -105,108 +44,12 @@
         touch_io->write(1);
         
         if (0x01 == touch_data[i]) {            // Threshold, get a touch
-            if(i==1){
-                modo=0;
-            }
-            else if(i==0){
-                modo=1;
-            }
+            keyboard.putc(key_map[i]);
         } else if (0x80 == touch_data[i]) {     // Last 7 measurement is under the threshold, touch is released
         }
     }
 }
 
-void drawVector(int theArray[5][5], neopixel::Pixel * vectorPixel, int r, int g, int b){
-    for(int i = 0;i<5;i++){
-        for(int j = 0; j<5;j++){
-            if(theArray[i][j] == 1)
-                fill_pixel(vectorPixel,i,j,r,g,b);
-            else
-                fill_pixel(vectorPixel,i,j,0,0,0); 
-        }
-    }
-}
-
-void drawColorPage(neopixel::Pixel buffer[25],int pag) {
-    // The pixel array control class.
-    neopixel::PixelArray array(DATA_PIN);
-    for (int i=0;i<5;i++) {
-        int pCol=(pag*5)+i;
-        for (int g=0; g<4; g++) {       
-            fill_pixel(buffer,g,i,palR[pCol],palG[pCol],palB[pCol]);
-        }
-        array.update(buffer, 64);
-    }     
-}
-
-void refreshScreen(neopixel::Pixel buffer[25]) {
-    // The pixel array control class.
-    neopixel::PixelArray array(DATA_PIN);
-    for (int i=0;i<25;i++) {
-        int posx=i%5;
-        int posy=int(i/5);    
-        fill_pixel(buffer,posx,posy,pantR[posx][posy],pantG[posx][posy],pantB[posx][posy]);
-    }
-    array.update(buffer, 64);
-}   
-
-
-void selectColor(neopixel::Pixel buffer[25]) {
-    neopixel::PixelArray array(DATA_PIN);
-    int posLed = ain.read() * 15.0f;
-    if (posLed>15) posLed=15;
-    int page=int(posLed/3);
-    int oldpage=page;
-    drawColorPage(buffer,page);
-    int oldLed=posLed;
-    while (1) {
-        int posLed = ain.read() * 15.0f;
-        if (posLed>15) posLed=15;
-        page=int(posLed/5);
-        if (oldpage!=page) {
-            // Draw a new color page
-            drawColorPage(buffer,page);
-            oldpage=page;
-        }
-        if (oldLed!=posLed) 
-        {
-            fill_pixel(buffer,5,oldLed%5,0,0,0);
-            oldLed=posLed;
-            fill_pixel(buffer,5,posLed%5,50,50,50);
-            array.update(buffer, 64);
-        }
-        if(pushbutton){
-            // Select color
-            int elColor=(page*5)+posLed%5;
-            actualR=palR[elColor];
-            actualG=palG[elColor];
-            actualB=palB[elColor];
-            wait_ms(50);
-            while (pushbutton) {wait_ms(10);}
-            // Repaint
-            refreshScreen(buffer);
-            break;
-        }
-    }
-}
-
-void clearScreen(neopixel::Pixel buffer[25], bool newDraw) {
-    // The pixel array control class.
-    neopixel::PixelArray array(DATA_PIN);
-    for (int i=0;i<25;i++) {
-        int posx=i%5;
-        int posy=int(i/5);    
-        fill_pixel(buffer,posx,posy,0,0,0);
-        if (newDraw) {
-            pantR[posx][posy]=0;
-            pantG[posx][posy]=0;
-            pantB[posx][posy]=0;
-        }
-    }
-    array.update(buffer, 64);
-}
-
-
 int main()
 {
     // Turn off miniblip buzzer
@@ -225,81 +68,20 @@
     // Create a temporary DigitalIn so we can configure the pull-down resistor.
     DigitalIn(DATA_PIN, PullDown);
     
-
-    
-    neopixel::Pixel vector[25];
-    void_matrix(vector);
-
-    // The pixel array control class.
-    neopixel::PixelArray array(DATA_PIN);
-    
-    bool pixState=0;
-    int pixCount=0;
-    int OldPos = ain.read() * 26.0f;
+    int OldPos = ain.read() * 15.0f;
 
     while (1) {
         // Read Pot
-        int posLed = ain.read() * 26.0f;
-        if (posLed>25) posLed=25;
-        if (posLed<0) posLed=0;
-        int posx=posLed%5;
-        int posy=int(posLed/5);
-        //fill_pixel(vector,posx,posy,actualR,actualG,actualB);
-        if (pixState) fill_pixel(vector,posx,posy,50,50,50); else {
-            int posx=posLed%5;
-            int posy=int(posLed/5);
-            int cred=pantR[posx][posy];
-            int cblu=pantG[posx][posy];
-            int cgreen=pantB[posx][posy];
-            fill_pixel(vector,posx,posy,cred,cblu,cgreen);
-        }
-        if (posLed!=OldPos) {
-            // Delete old pos
-            int posx=OldPos%5;
-            int posy=int(OldPos/5);
-            int cred=pantR[posx][posy];
-            int cblu=pantG[posx][posy];
-            int cgreen=pantB[posx][posy];
-            fill_pixel(vector,posx,posy,cred,cblu,cgreen);
-            OldPos=posLed;
-        }
-            
-        pixCount++;
-        if (pixCount>8) {
-            pixCount=0;
-            pixState^= 1;
+        int posJoy = ain.read() * 15.0f;   
+        if (posJoy!=OldPos) {
+            OldPos=posJoy;
+            keyboard.putc(posJoy+65);
         }
-        array.update(vector, 64);
-        wait_ms(30); 
-       
-        // Color button
-        if (modo==1) {
-                clearScreen(vector,false);
-                selectColor(vector);
-            modo=10;
-        }
-              
-        // Change pixel
-        if(pushbutton){
-            //Check
-            int posx=posLed%5;
-            int posy=int(posLed/5);
-            int cred=pantR[posx][posy];
-            int cblu=pantG[posx][posy];
-            int cgreen=pantB[posx][posy];
-            if (cred==0&&cblu==0&cgreen==0) {
-                pantR[posx][posy]=actualR;
-                pantG[posx][posy]=actualG;
-                pantB[posx][posy]=actualB;
-            }
-            else {
-                pantR[posx][posy]=0;
-                pantG[posx][posy]=0;
-                pantB[posx][posy]=0;  
-            }  
-            //fill_pixel(vector,posx,posy,cred,cblu,cgreen);
-            wait_ms(50);
+        if(pushbutton) {
+            keyboard.printf("!");
             while (pushbutton) {wait_ms(10);}
         }
+
+        
     }
 }
\ No newline at end of file