Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of blip_dado by
main.cpp@5:03859160e3a9, 2015-12-01 (annotated)
- Committer:
- pighixxx
- Date:
- Tue Dec 01 15:09:48 2015 +0000
- Revision:
- 5:03859160e3a9
- Parent:
- 4:55d1628dd2e5
- Child:
- 6:cacc8514502c
miniBLIP - paint on matrix
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| pighixxx | 4:55d1628dd2e5 | 1 | // miniblip led dado demo |
| pighixxx | 3:2d84c8262139 | 2 | |
| JacobBramley | 0:60499ad28ea9 | 3 | #include "mbed.h" |
| JacobBramley | 1:ca76237d2965 | 4 | #include "neopixel.h" |
| JacobBramley | 0:60499ad28ea9 | 5 | |
| pighixxx | 3:2d84c8262139 | 6 | // Matrix led output pin |
| pighixxx | 3:2d84c8262139 | 7 | #define DATA_PIN P0_9 |
| JacobBramley | 0:60499ad28ea9 | 8 | |
| pighixxx | 4:55d1628dd2e5 | 9 | #define ANALOG_PHOTO P0_16 |
| pighixxx | 4:55d1628dd2e5 | 10 | #define ANALOG_POTENTIOMETER P0_22 |
| pighixxx | 4:55d1628dd2e5 | 11 | #define ANALOG_BUZZER P0_8 |
| pighixxx | 4:55d1628dd2e5 | 12 | #define DIGITAL_CIRCLE P0_12 |
| pighixxx | 4:55d1628dd2e5 | 13 | |
| pighixxx | 4:55d1628dd2e5 | 14 | AnalogIn ain(ANALOG_POTENTIOMETER); |
| pighixxx | 4:55d1628dd2e5 | 15 | |
| pighixxx | 4:55d1628dd2e5 | 16 | void fill_pixel(neopixel::Pixel buffer[25], int x, int y, int red, int green, int blue){ |
| pighixxx | 4:55d1628dd2e5 | 17 | |
| pighixxx | 4:55d1628dd2e5 | 18 | if(x<0) x=0; |
| pighixxx | 4:55d1628dd2e5 | 19 | if(x>4) x=4; |
| pighixxx | 4:55d1628dd2e5 | 20 | if(y<0) y=0; |
| pighixxx | 4:55d1628dd2e5 | 21 | if(y>4) y=4; |
| pighixxx | 4:55d1628dd2e5 | 22 | |
| pighixxx | 4:55d1628dd2e5 | 23 | |
| pighixxx | 4:55d1628dd2e5 | 24 | int posicion=x+y*5; |
| pighixxx | 4:55d1628dd2e5 | 25 | buffer[posicion].red=red; |
| pighixxx | 4:55d1628dd2e5 | 26 | buffer[posicion].green=green; |
| pighixxx | 4:55d1628dd2e5 | 27 | buffer[posicion].blue=blue; |
| pighixxx | 4:55d1628dd2e5 | 28 | } |
| pighixxx | 4:55d1628dd2e5 | 29 | |
| pighixxx | 4:55d1628dd2e5 | 30 | void void_matrix(neopixel::Pixel aux[25], int tam=25){ |
| pighixxx | 4:55d1628dd2e5 | 31 | |
| pighixxx | 4:55d1628dd2e5 | 32 | for(int i=0;i<tam;i++){ |
| pighixxx | 4:55d1628dd2e5 | 33 | aux[i].red=0; |
| pighixxx | 4:55d1628dd2e5 | 34 | aux[i].green=0; |
| pighixxx | 4:55d1628dd2e5 | 35 | aux[i].blue=0; |
| pighixxx | 4:55d1628dd2e5 | 36 | } |
| JacobBramley | 0:60499ad28ea9 | 37 | } |
| JacobBramley | 0:60499ad28ea9 | 38 | |
| pighixxx | 5:03859160e3a9 | 39 | int pant[5][5] = { |
| pighixxx | 5:03859160e3a9 | 40 | {0,0,0,0,0}, |
| pighixxx | 5:03859160e3a9 | 41 | {0,0,0,0,0}, |
| pighixxx | 4:55d1628dd2e5 | 42 | {0,0,0,0,0}, |
| pighixxx | 4:55d1628dd2e5 | 43 | {0,0,0,0,0}, |
| pighixxx | 5:03859160e3a9 | 44 | {0,0,0,0,0} |
| pighixxx | 5:03859160e3a9 | 45 | }; |
| pighixxx | 5:03859160e3a9 | 46 | |
| pighixxx | 5:03859160e3a9 | 47 | int pantR[5][5] = { |
| pighixxx | 5:03859160e3a9 | 48 | {0,0,0,0,0}, |
| pighixxx | 5:03859160e3a9 | 49 | {30,0,0,0,0}, |
| pighixxx | 5:03859160e3a9 | 50 | {0,0,0,0,0}, |
| pighixxx | 4:55d1628dd2e5 | 51 | {0,0,0,0,0}, |
| pighixxx | 4:55d1628dd2e5 | 52 | {0,0,0,0,0} |
| pighixxx | 4:55d1628dd2e5 | 53 | }; |
| pighixxx | 4:55d1628dd2e5 | 54 | |
| pighixxx | 5:03859160e3a9 | 55 | int pantG[5][5] = { |
| pighixxx | 5:03859160e3a9 | 56 | {0,0,0,0,0}, |
| pighixxx | 4:55d1628dd2e5 | 57 | {0,0,0,0,0}, |
| pighixxx | 4:55d1628dd2e5 | 58 | {0,0,0,0,0}, |
| pighixxx | 4:55d1628dd2e5 | 59 | {0,0,0,0,0}, |
| pighixxx | 5:03859160e3a9 | 60 | {0,0,0,0,0} |
| pighixxx | 4:55d1628dd2e5 | 61 | }; |
| pighixxx | 4:55d1628dd2e5 | 62 | |
| pighixxx | 5:03859160e3a9 | 63 | int pantB[5][5] = { |
| pighixxx | 4:55d1628dd2e5 | 64 | {0,0,0,0,0}, |
| pighixxx | 4:55d1628dd2e5 | 65 | {0,0,0,0,0}, |
| pighixxx | 4:55d1628dd2e5 | 66 | {0,0,0,0,0}, |
| pighixxx | 5:03859160e3a9 | 67 | {0,0,0,0,0}, |
| pighixxx | 5:03859160e3a9 | 68 | {0,0,0,0,0} |
| pighixxx | 4:55d1628dd2e5 | 69 | }; |
| pighixxx | 5:03859160e3a9 | 70 | |
| pighixxx | 5:03859160e3a9 | 71 | |
| pighixxx | 4:55d1628dd2e5 | 72 | |
| pighixxx | 4:55d1628dd2e5 | 73 | void drawVector(int theArray[5][5], neopixel::Pixel * vectorPixel, int r, int g, int b){ |
| pighixxx | 4:55d1628dd2e5 | 74 | for(int i = 0;i<5;i++){ |
| pighixxx | 4:55d1628dd2e5 | 75 | for(int j = 0; j<5;j++){ |
| pighixxx | 4:55d1628dd2e5 | 76 | if(theArray[i][j] == 1) |
| pighixxx | 4:55d1628dd2e5 | 77 | fill_pixel(vectorPixel,i,j,r,g,b); |
| pighixxx | 4:55d1628dd2e5 | 78 | else |
| pighixxx | 4:55d1628dd2e5 | 79 | fill_pixel(vectorPixel,i,j,0,0,0); |
| pighixxx | 4:55d1628dd2e5 | 80 | } |
| pighixxx | 4:55d1628dd2e5 | 81 | } |
| pighixxx | 4:55d1628dd2e5 | 82 | } |
| JacobBramley | 1:ca76237d2965 | 83 | int main() |
| JacobBramley | 1:ca76237d2965 | 84 | { |
| pighixxx | 3:2d84c8262139 | 85 | // Turn off miniblip buzzer |
| pighixxx | 3:2d84c8262139 | 86 | PwmOut speaker(P0_8); |
| pighixxx | 3:2d84c8262139 | 87 | speaker=0.0; |
| JacobBramley | 1:ca76237d2965 | 88 | // Create a temporary DigitalIn so we can configure the pull-down resistor. |
| JacobBramley | 1:ca76237d2965 | 89 | DigitalIn(DATA_PIN, PullDown); |
| pighixxx | 4:55d1628dd2e5 | 90 | |
| pighixxx | 4:55d1628dd2e5 | 91 | // Pushbutton |
| pighixxx | 4:55d1628dd2e5 | 92 | DigitalIn pushbutton(P0_23); |
| pighixxx | 4:55d1628dd2e5 | 93 | |
| pighixxx | 4:55d1628dd2e5 | 94 | neopixel::Pixel vector[25]; |
| pighixxx | 4:55d1628dd2e5 | 95 | void_matrix(vector); |
| JacobBramley | 1:ca76237d2965 | 96 | |
| JacobBramley | 1:ca76237d2965 | 97 | // The pixel array control class. |
| JacobBramley | 1:ca76237d2965 | 98 | neopixel::PixelArray array(DATA_PIN); |
| pighixxx | 5:03859160e3a9 | 99 | |
| pighixxx | 5:03859160e3a9 | 100 | bool pixState=0; |
| pighixxx | 5:03859160e3a9 | 101 | int pixCount=0; |
| pighixxx | 5:03859160e3a9 | 102 | int OldPos = ain.read() * 26.0f; |
| pighixxx | 5:03859160e3a9 | 103 | |
| pighixxx | 5:03859160e3a9 | 104 | int color=0; |
| pighixxx | 5:03859160e3a9 | 105 | |
| JacobBramley | 1:ca76237d2965 | 106 | while (1) { |
| pighixxx | 5:03859160e3a9 | 107 | // Read Pot |
| pighixxx | 5:03859160e3a9 | 108 | int posLed = ain.read() * 26.0f; |
| pighixxx | 5:03859160e3a9 | 109 | |
| pighixxx | 4:55d1628dd2e5 | 110 | int posx=posLed%5; |
| pighixxx | 4:55d1628dd2e5 | 111 | int posy=int(posLed/5); |
| pighixxx | 5:03859160e3a9 | 112 | if (pixState) fill_pixel(vector,posx,posy,30,30,30); else { |
| pighixxx | 5:03859160e3a9 | 113 | int posx=posLed%5; |
| pighixxx | 5:03859160e3a9 | 114 | int posy=int(posLed/5); |
| pighixxx | 5:03859160e3a9 | 115 | int cred=pantR[posx][posy]; |
| pighixxx | 5:03859160e3a9 | 116 | int cblu=pantG[posx][posy]; |
| pighixxx | 5:03859160e3a9 | 117 | int cgreen=pantB[posx][posy]; |
| pighixxx | 5:03859160e3a9 | 118 | fill_pixel(vector,posx,posy,cred,cblu,cgreen); |
| pighixxx | 5:03859160e3a9 | 119 | } |
| pighixxx | 5:03859160e3a9 | 120 | if (posLed!=OldPos) { |
| pighixxx | 5:03859160e3a9 | 121 | // Delete old pos |
| pighixxx | 5:03859160e3a9 | 122 | int posx=OldPos%5; |
| pighixxx | 5:03859160e3a9 | 123 | int posy=int(OldPos/5); |
| pighixxx | 5:03859160e3a9 | 124 | int cred=pantR[posx][posy]; |
| pighixxx | 5:03859160e3a9 | 125 | int cblu=pantG[posx][posy]; |
| pighixxx | 5:03859160e3a9 | 126 | int cgreen=pantB[posx][posy]; |
| pighixxx | 5:03859160e3a9 | 127 | fill_pixel(vector,posx,posy,cred,cblu,cgreen); |
| pighixxx | 5:03859160e3a9 | 128 | OldPos=posLed; |
| pighixxx | 5:03859160e3a9 | 129 | } |
| pighixxx | 5:03859160e3a9 | 130 | |
| pighixxx | 5:03859160e3a9 | 131 | pixCount++; |
| pighixxx | 5:03859160e3a9 | 132 | if (pixCount>10) { |
| pighixxx | 5:03859160e3a9 | 133 | pixCount=0; |
| pighixxx | 5:03859160e3a9 | 134 | pixState^= 1; |
| pighixxx | 5:03859160e3a9 | 135 | } |
| pighixxx | 4:55d1628dd2e5 | 136 | array.update(vector, 64); |
| pighixxx | 4:55d1628dd2e5 | 137 | wait_ms(30); |
| pighixxx | 5:03859160e3a9 | 138 | |
| pighixxx | 5:03859160e3a9 | 139 | |
| pighixxx | 4:55d1628dd2e5 | 140 | // Wait button |
| pighixxx | 4:55d1628dd2e5 | 141 | if(pushbutton){ |
| pighixxx | 5:03859160e3a9 | 142 | //Check |
| pighixxx | 5:03859160e3a9 | 143 | int posx=posLed%5; |
| pighixxx | 5:03859160e3a9 | 144 | int posy=int(posLed/5); |
| pighixxx | 5:03859160e3a9 | 145 | int cred=pantR[posx][posy]; |
| pighixxx | 5:03859160e3a9 | 146 | int cblu=pantG[posx][posy]; |
| pighixxx | 5:03859160e3a9 | 147 | int cgreen=pantB[posx][posy]; |
| pighixxx | 5:03859160e3a9 | 148 | if (cred==0&&cblu==0&cgreen==0) color=30; else color=0; |
| pighixxx | 5:03859160e3a9 | 149 | pantR[posx][posy]=color; |
| pighixxx | 5:03859160e3a9 | 150 | pantG[posx][posy]=0; |
| pighixxx | 5:03859160e3a9 | 151 | pantB[posx][posy]=0; |
| pighixxx | 5:03859160e3a9 | 152 | //fill_pixel(vector,posx,posy,cred,cblu,cgreen); |
| pighixxx | 5:03859160e3a9 | 153 | wait_ms(50); |
| pighixxx | 4:55d1628dd2e5 | 154 | } |
| JacobBramley | 0:60499ad28ea9 | 155 | } |
| pighixxx | 4:55d1628dd2e5 | 156 | } |
