test
Dependencies: PixelArray USBDevice mbed
Fork of blip_analog by
main.cpp@3:dacbf2b208f5, 2015-11-30 (annotated)
- Committer:
- paclema
- Date:
- Mon Nov 30 14:38:13 2015 +0000
- Revision:
- 3:dacbf2b208f5
- Parent:
- 2:7734a904c531
last commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
paclema | 3:dacbf2b208f5 | 1 | // potenciometro controla la matriz |
paclema | 3:dacbf2b208f5 | 2 | // y buzzer al mismo tiempo envia por |
paclema | 3:dacbf2b208f5 | 3 | // el puerto serie |
paclema | 3:dacbf2b208f5 | 4 | |
paclema | 3:dacbf2b208f5 | 5 | #include "mbed.h" |
paclema | 3:dacbf2b208f5 | 6 | #include "neopixel.h" |
paclema | 3:dacbf2b208f5 | 7 | #include "USBSerial.h" |
paclema | 3:dacbf2b208f5 | 8 | |
paclema | 3:dacbf2b208f5 | 9 | // Matrix led output pin |
paclema | 3:dacbf2b208f5 | 10 | #define MATRIX_PIN P0_9 |
paclema | 3:dacbf2b208f5 | 11 | #define NLEDS 25 |
paclema | 3:dacbf2b208f5 | 12 | |
paclema | 3:dacbf2b208f5 | 13 | |
paclema | 3:dacbf2b208f5 | 14 | AnalogIn ain(P0_22); |
pighixxx | 2:7734a904c531 | 15 | |
paclema | 3:dacbf2b208f5 | 16 | unsigned int counter = 0; |
paclema | 3:dacbf2b208f5 | 17 | USBSerial serial; |
paclema | 3:dacbf2b208f5 | 18 | |
paclema | 3:dacbf2b208f5 | 19 | neopixel::Pixel buffer[NLEDS]; |
paclema | 3:dacbf2b208f5 | 20 | PwmOut speaker(P0_8); |
paclema | 3:dacbf2b208f5 | 21 | |
sam_grove | 0:101a12a915c6 | 22 | |
paclema | 3:dacbf2b208f5 | 23 | void setPixel(uint32_t posicion, uint8_t red, uint8_t green, uint8_t blue) { |
paclema | 3:dacbf2b208f5 | 24 | buffer[posicion].red=red; |
paclema | 3:dacbf2b208f5 | 25 | buffer[posicion].green=green; |
paclema | 3:dacbf2b208f5 | 26 | buffer[posicion].blue=blue; |
paclema | 3:dacbf2b208f5 | 27 | } |
paclema | 3:dacbf2b208f5 | 28 | |
paclema | 3:dacbf2b208f5 | 29 | |
paclema | 3:dacbf2b208f5 | 30 | int main() |
paclema | 3:dacbf2b208f5 | 31 | { |
paclema | 3:dacbf2b208f5 | 32 | // Turn off miniblip buzzer |
paclema | 3:dacbf2b208f5 | 33 | speaker=0.0; |
pighixxx | 2:7734a904c531 | 34 | |
paclema | 3:dacbf2b208f5 | 35 | serial.printf("Hello world!\n"); |
paclema | 3:dacbf2b208f5 | 36 | DigitalIn(MATRIX_PIN, PullDown); |
paclema | 3:dacbf2b208f5 | 37 | |
paclema | 3:dacbf2b208f5 | 38 | while(true) { |
paclema | 3:dacbf2b208f5 | 39 | float pot = ain.read()*24; |
paclema | 3:dacbf2b208f5 | 40 | //serial.printf("mini blip is alive for %i seconds.\n", counter); |
paclema | 3:dacbf2b208f5 | 41 | serial.printf("Pot: %f\n", pot); |
paclema | 3:dacbf2b208f5 | 42 | counter++; |
paclema | 3:dacbf2b208f5 | 43 | |
paclema | 3:dacbf2b208f5 | 44 | neopixel::PixelArray array(MATRIX_PIN); |
paclema | 3:dacbf2b208f5 | 45 | |
paclema | 3:dacbf2b208f5 | 46 | for(int i=0;i<NLEDS;i++) { |
paclema | 3:dacbf2b208f5 | 47 | setPixel(i, 0, 0, 0); |
paclema | 3:dacbf2b208f5 | 48 | } |
paclema | 3:dacbf2b208f5 | 49 | |
paclema | 3:dacbf2b208f5 | 50 | if (pot >= 100) pot =100; |
paclema | 3:dacbf2b208f5 | 51 | setPixel(pot, 0, 20, 0); |
paclema | 3:dacbf2b208f5 | 52 | |
paclema | 3:dacbf2b208f5 | 53 | /* |
paclema | 3:dacbf2b208f5 | 54 | float note=200*(pot); |
paclema | 3:dacbf2b208f5 | 55 | speaker.period(1.0/note); |
paclema | 3:dacbf2b208f5 | 56 | speaker = 50.0; |
paclema | 3:dacbf2b208f5 | 57 | */ |
paclema | 3:dacbf2b208f5 | 58 | array.update(buffer, NLEDS); |
paclema | 3:dacbf2b208f5 | 59 | wait_ms(10); |
sam_grove | 0:101a12a915c6 | 60 | |
sam_grove | 0:101a12a915c6 | 61 | } |
paclema | 3:dacbf2b208f5 | 62 | |
paclema | 3:dacbf2b208f5 | 63 | // |
paclema | 3:dacbf2b208f5 | 64 | // // Create a temporary DigitalIn so we can configure the pull-down resistor. |
paclema | 3:dacbf2b208f5 | 65 | // DigitalIn(DATA_PIN, PullDown); |
paclema | 3:dacbf2b208f5 | 66 | // |
paclema | 3:dacbf2b208f5 | 67 | // // The pixel array control class. |
paclema | 3:dacbf2b208f5 | 68 | // neopixel::PixelArray array(DATA_PIN); |
paclema | 3:dacbf2b208f5 | 69 | // |
paclema | 3:dacbf2b208f5 | 70 | // uint32_t offset = 0; |
paclema | 3:dacbf2b208f5 | 71 | // uint32_t i = 1; |
paclema | 3:dacbf2b208f5 | 72 | // while (1) { |
paclema | 3:dacbf2b208f5 | 73 | // array.update(generate, 64, offset++); |
paclema | 3:dacbf2b208f5 | 74 | // |
paclema | 3:dacbf2b208f5 | 75 | // //Play Sound |
paclema | 3:dacbf2b208f5 | 76 | // float note=500+(i*100); |
paclema | 3:dacbf2b208f5 | 77 | // speaker.period(1.0/note); |
paclema | 3:dacbf2b208f5 | 78 | // //speaker = float(i)/50.0; |
paclema | 3:dacbf2b208f5 | 79 | // |
paclema | 3:dacbf2b208f5 | 80 | // i++; |
paclema | 3:dacbf2b208f5 | 81 | // if (i>10) i=1; |
paclema | 3:dacbf2b208f5 | 82 | // // Rainbow delay |
paclema | 3:dacbf2b208f5 | 83 | // wait_ms(100); |
paclema | 3:dacbf2b208f5 | 84 | // } |
sam_grove | 0:101a12a915c6 | 85 | } |
paclema | 3:dacbf2b208f5 | 86 |