test
Dependencies: PixelArray USBDevice mbed
Fork of blip_analog by
Diff: main.cpp
- Revision:
- 3:dacbf2b208f5
- Parent:
- 2:7734a904c531
--- a/main.cpp Thu Nov 26 09:25:10 2015 +0000 +++ b/main.cpp Mon Nov 30 14:38:13 2015 +0000 @@ -1,21 +1,86 @@ -// miniblip analog in +// 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 MATRIX_PIN P0_9 +#define NLEDS 25 + + +AnalogIn ain(P0_22); -// photoresistor: P0_23 -// external analogs: P0_15, P0_14, P0_13, P0_12, P0_11 - -#include "mbed.h" +unsigned int counter = 0; +USBSerial serial; + +neopixel::Pixel buffer[NLEDS]; +PwmOut speaker(P0_8); + -// Initialize a pins to perform analog input and digital output fucntions -AnalogIn ain(P0_23); +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 + speaker=0.0; -Serial pc(USBTX, USBRX); + serial.printf("Hello world!\n"); + DigitalIn(MATRIX_PIN, PullDown); + + while(true) { + float pot = ain.read()*24; + //serial.printf("mini blip is alive for %i seconds.\n", counter); + serial.printf("Pot: %f\n", pot); + counter++; + + neopixel::PixelArray array(MATRIX_PIN); + + for(int i=0;i<NLEDS;i++) { + setPixel(i, 0, 0, 0); + } + + if (pot >= 100) pot =100; + setPixel(pot, 0, 20, 0); + + /* + float note=200*(pot); + speaker.period(1.0/note); + speaker = 50.0; + */ + array.update(buffer, NLEDS); + wait_ms(10); -int main(void) -{ - while (1) { - // print the percentage and 16 bit normalized values - pc.printf("Perc: %3.3f%%\n", ain.read()*100.0f); - pc.printf("Norm: 0x%04X \n", ain.read_u16()); - wait(0.2f); } + + // +// // 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++); +// +// //Play Sound +// float note=500+(i*100); +// speaker.period(1.0/note); +// //speaker = float(i)/50.0; +// +// i++; +// if (i>10) i=1; +// // Rainbow delay +// wait_ms(100); +// } } +