![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Un script para cambiar el color
Dependencies: PixelArray USBDevice mbed
Fork of blip_rainbow_ejemplo by
main.cpp@7:e5c1d481ad40, 2015-11-30 (annotated)
- Committer:
- jjmerelo
- Date:
- Mon Nov 30 12:14:18 2015 +0000
- Revision:
- 7:e5c1d481ad40
- Parent:
- 6:482c4dccb291
- Child:
- 8:ef1c8d16f063
Cambiando colores
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jjmerelo | 4:8eac4e92928a | 1 | // potenciometro controla la matriz |
jjmerelo | 4:8eac4e92928a | 2 | // y buzzer al mismo tiempo envia por |
jjmerelo | 4:8eac4e92928a | 3 | // el puerto serie |
pighixxx | 3:2d84c8262139 | 4 | |
JacobBramley | 0:60499ad28ea9 | 5 | #include "mbed.h" |
JacobBramley | 1:ca76237d2965 | 6 | #include "neopixel.h" |
jjmerelo | 4:8eac4e92928a | 7 | #include "USBSerial.h" |
JacobBramley | 0:60499ad28ea9 | 8 | |
pighixxx | 3:2d84c8262139 | 9 | // Matrix led output pin |
jjmerelo | 4:8eac4e92928a | 10 | #define MATRIX_PIN P0_9 |
jjmerelo | 4:8eac4e92928a | 11 | #define NLEDS 25 |
jjmerelo | 4:8eac4e92928a | 12 | |
jjmerelo | 4:8eac4e92928a | 13 | AnalogIn ain(P0_22); |
jjmerelo | 4:8eac4e92928a | 14 | |
jjmerelo | 4:8eac4e92928a | 15 | unsigned int counter = 0; |
jjmerelo | 4:8eac4e92928a | 16 | USBSerial serial; |
JacobBramley | 0:60499ad28ea9 | 17 | |
jjmerelo | 4:8eac4e92928a | 18 | neopixel::Pixel buffer[NLEDS]; |
jjmerelo | 4:8eac4e92928a | 19 | PwmOut speaker(P0_8); |
jjmerelo | 4:8eac4e92928a | 20 | |
jjmerelo | 4:8eac4e92928a | 21 | void setPixel(uint32_t posicion, uint8_t red, uint8_t green, uint8_t blue) { |
jjmerelo | 4:8eac4e92928a | 22 | buffer[posicion].red=red; |
jjmerelo | 4:8eac4e92928a | 23 | buffer[posicion].green=green; |
jjmerelo | 4:8eac4e92928a | 24 | buffer[posicion].blue=blue; |
JacobBramley | 0:60499ad28ea9 | 25 | } |
JacobBramley | 0:60499ad28ea9 | 26 | |
JacobBramley | 1:ca76237d2965 | 27 | int main() |
JacobBramley | 1:ca76237d2965 | 28 | { |
pighixxx | 3:2d84c8262139 | 29 | // Turn off miniblip buzzer |
pighixxx | 3:2d84c8262139 | 30 | speaker=0.0; |
JacobBramley | 1:ca76237d2965 | 31 | |
jjmerelo | 4:8eac4e92928a | 32 | serial.printf("Hello world!\n"); |
jjmerelo | 4:8eac4e92928a | 33 | while(true) { |
jjmerelo | 6:482c4dccb291 | 34 | float pot = ain.read() * 50.0f; |
jjmerelo | 4:8eac4e92928a | 35 | serial.printf("mini blip is alive for %i seconds.\n", counter); |
jjmerelo | 4:8eac4e92928a | 36 | serial.printf("Pot: %3.3f%%\n", pot); |
jjmerelo | 4:8eac4e92928a | 37 | counter++; |
jjmerelo | 4:8eac4e92928a | 38 | |
jjmerelo | 4:8eac4e92928a | 39 | neopixel::PixelArray array(MATRIX_PIN); |
jjmerelo | 4:8eac4e92928a | 40 | for(int i=0;i<NLEDS;i++) { |
jjmerelo | 7:e5c1d481ad40 | 41 | setPixel(i, pot, 255-pot, 255-pot); |
jjmerelo | 4:8eac4e92928a | 42 | } |
pighixxx | 3:2d84c8262139 | 43 | |
jjmerelo | 7:e5c1d481ad40 | 44 | float note=500+(pot)/100; |
jjmerelo | 4:8eac4e92928a | 45 | speaker.period(1.0/note); |
jjmerelo | 4:8eac4e92928a | 46 | speaker = 50.0; |
pighixxx | 3:2d84c8262139 | 47 | |
jjmerelo | 7:e5c1d481ad40 | 48 | array.update(buffer, NLEDS); |
jjmerelo | 4:8eac4e92928a | 49 | |
JacobBramley | 0:60499ad28ea9 | 50 | } |
jjmerelo | 4:8eac4e92928a | 51 | |
jjmerelo | 4:8eac4e92928a | 52 | }// miniblip led matrix demo |