Un script para cambiar el color

Dependencies:   PixelArray USBDevice mbed

Fork of blip_rainbow_ejemplo by JJ Merelo

Committer:
jjmerelo
Date:
Mon Nov 30 12:39:43 2015 +0000
Revision:
8:ef1c8d16f063
Parent:
7:e5c1d481ad40
Child:
9:297dd05aecfd
Con colorines

Who changed what in which revision?

UserRevisionLine numberNew 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 8:ef1c8d16f063 39 int rgb = 20* floor( pot/50 );
jjmerelo 4:8eac4e92928a 40 neopixel::PixelArray array(MATRIX_PIN);
jjmerelo 4:8eac4e92928a 41 for(int i=0;i<NLEDS;i++) {
jjmerelo 8:ef1c8d16f063 42 setPixel(i, rgb, 255-rgb, 255-rgb);
jjmerelo 4:8eac4e92928a 43 }
jjmerelo 8:ef1c8d16f063 44
jjmerelo 8:ef1c8d16f063 45 array.update(buffer, NLEDS);
jjmerelo 8:ef1c8d16f063 46 wait(10);
jjmerelo 4:8eac4e92928a 47
JacobBramley 0:60499ad28ea9 48 }
jjmerelo 4:8eac4e92928a 49
jjmerelo 4:8eac4e92928a 50 }// miniblip led matrix demo