miniBLIP - paint on matrix

Dependencies:   USBDevice mbed

Fork of blip_dado by Alberto Piganti

Revision:
5:03859160e3a9
Parent:
4:55d1628dd2e5
Child:
6:cacc8514502c
--- a/main.cpp	Tue Dec 01 14:26:03 2015 +0000
+++ b/main.cpp	Tue Dec 01 15:09:48 2015 +0000
@@ -36,53 +36,39 @@
     }
 }
 
-int dado_1[5][5] = {
+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,1,0,0},
+{0,0,0,0,0}
+};
+
+int pantR[5][5] = {
+{0,0,0,0,0},
+{30,0,0,0,0},
+{0,0,0,0,0},
 {0,0,0,0,0},
 {0,0,0,0,0}
 };
 
-int dado_2[5][5] = {
-{0,0,0,0,1},
+int pantG[5][5] = {
+{0,0,0,0,0},
 {0,0,0,0,0},
 {0,0,0,0,0},
 {0,0,0,0,0},
-{1,0,0,0,0}
-};
-    
-int dado_3[5][5] = {
-{0,0,0,0,1},
-{0,0,0,0,0},
-{0,0,1,0,0},
-{0,0,0,0,0},
-{1,0,0,0,0}
+{0,0,0,0,0}
 };
 
-int dado_4[5][5] = {
-{1,0,0,0,1},
+int pantB[5][5] = {
 {0,0,0,0,0},
 {0,0,0,0,0},
 {0,0,0,0,0},
-{1,0,0,0,1}
+{0,0,0,0,0},
+{0,0,0,0,0}
 };
- 
-int dado_5[5][5] = {
-{1,0,0,0,1},
-{0,0,0,0,0},
-{0,0,1,0,0},
-{0,0,0,0,0},
-{1,0,0,0,1}
-};
- 
-int dado_6[5][5] = {
-{1,0,0,0,1},
-{0,0,0,0,0},
-{1,0,0,0,1},
-{0,0,0,0,0},
-{1,0,0,0,1}
-};
+
+
 
 void drawVector(int theArray[5][5], neopixel::Pixel * vectorPixel, int r, int g, int b){
     for(int i = 0;i<5;i++){
@@ -110,66 +96,61 @@
 
     // The pixel array control class.
     neopixel::PixelArray array(DATA_PIN);
-    int posLed=0;
-    int cred=10;
-    int cblue=10;
-    int cgreen=10;
+    
+    bool pixState=0;
+    int pixCount=0;
+    int OldPos = ain.read() * 26.0f;
+    
+    int color=0;
+    
     while (1) {
-        // Wait screen
+        // Read Pot
+        int posLed = ain.read() * 26.0f;
+        
         int posx=posLed%5;
         int posy=int(posLed/5);
-        fill_pixel(vector,posx,posy,cred,cblue,cgreen);
+        if (pixState) fill_pixel(vector,posx,posy,30,30,30); 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>10) {
+            pixCount=0;
+            pixState^= 1;
+        }
         array.update(vector, 64);
         wait_ms(30); 
-        posLed++;
-        if (posLed>24) {
-            cred=int(rand()%50);
-            cblue=int(rand()%50);
-            cgreen=int(rand()%50);
-            posLed=0;
-        } 
+       
+        
         // Wait button
         if(pushbutton){
-            posLed=0;
-            float pot = ain.read() * 100.0f;
-            int startdelay=10;
-            int face=1;
-            int red=10;
-            while (1) {
-                if (startdelay>300+(pot*3)) red=200;
-                switch(face) {
-                    case 1:
-                        drawVector(dado_1,vector,red,200-red,200-red);
-                        break;
-                    case 2:
-                        drawVector(dado_2,vector,red,200-red,200-red);
-                        break;
-                    case 3:
-                        drawVector(dado_3,vector,red,200-red,200-red);
-                        break;
-                    case 4:
-                        drawVector(dado_4,vector,red,200-red,200-red);
-                        break;
-                    case 5:
-                        drawVector(dado_5,vector,red,200-red,200-red);
-                        break;
-                    case 6:
-                        drawVector(dado_6,vector,red,200-red,200-red);
-                        break;
-                }
-                array.update(vector, 64);
-                if (startdelay>300+(pot*3)) break;
-                face++;
-                startdelay=startdelay+10;
-                
-                if (face>6) face=1;
-                wait_ms(startdelay);
-                
-            }
-            speaker=5.0;
-            wait_ms(1000);
-            speaker=0.0;
-            wait_ms(2500);
+            //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) color=30; else color=0;
+            pantR[posx][posy]=color;
+            pantG[posx][posy]=0;
+            pantB[posx][posy]=0;
+            //fill_pixel(vector,posx,posy,cred,cblu,cgreen);
+            wait_ms(50);
         }
     }
 }
\ No newline at end of file