Un script para cambiar el color
Dependencies: PixelArray USBDevice mbed
Fork of blip_rainbow_ejemplo by
Diff: main.cpp
- Revision:
- 4:8eac4e92928a
- Parent:
- 3:2d84c8262139
- Child:
- 6:482c4dccb291
diff -r 2d84c8262139 -r 8eac4e92928a main.cpp --- a/main.cpp Thu Nov 26 09:28:37 2015 +0000 +++ b/main.cpp Mon Nov 30 11:25:12 2015 +0000 @@ -1,43 +1,56 @@ -// miniblip led matrix demo +// potenciometro controla la matriz +// y buzzer al mismo tiempo envia por +// el puerto serie #include "mbed.h" #include "neopixel.h" +#include "USBSerial.h" // Matrix led output pin -#define DATA_PIN P0_9 +#define MATRIX_PIN P0_9 +#define NLEDS 25 + + +AnalogIn ain(P0_22); + +unsigned int counter = 0; +USBSerial serial; -void generate(neopixel::Pixel * out, uint32_t index, uintptr_t extra) -{ - uint32_t brightness = (index + extra) >> 3; - out->red = ((index + extra) & 0x1) ? brightness : 0; - out->green = ((index + extra) & 0x2) ? brightness : 0; - out->blue = ((index + extra) & 0x4) ? brightness : 0; +neopixel::Pixel buffer[NLEDS]; +PwmOut speaker(P0_8); + + +void setPixel(uint32_t posicion, uint8_t red, uint8_t green, uint8_t blue) { + buffer[posicion].red=red; + buffer[posicion].green=green; + buffer[posicion].blue=blue; } + int main() { // Turn off miniblip buzzer - PwmOut speaker(P0_8); speaker=0.0; - // Create a temporary DigitalIn so we can configure the pull-down resistor. - DigitalIn(DATA_PIN, PullDown); - - // The pixel array control class. - neopixel::PixelArray array(DATA_PIN); - uint32_t offset = 0; - uint32_t i = 1; - while (1) { - array.update(generate, 64, offset++); + serial.printf("Hello world!\n"); + while(true) { + float pot = ain.read() * 100.0f; + serial.printf("mini blip is alive for %i seconds.\n", counter); + serial.printf("Pot: %3.3f%%\n", pot); + counter++; + + neopixel::PixelArray array(MATRIX_PIN); + for(int i=0;i<NLEDS;i++) { + setPixel(i, pot, 0, 0); + } - //Play Sound - float note=500+(i*100); - //speaker.period(1.0/note); - //speaker = float(i)/50.0; + float note=500+(pot); + speaker.period(1.0/note); + speaker = 50.0; - i++; - if (i>10) i=1; - // Rainbow delay - wait_ms(100); + array.update(buffer, NLEDS); + //wait(1); + } -} + +}// miniblip led matrix demo