Pablo Clemente / Mbed 2 deprecated blip_analog

Dependencies:   PixelArray USBDevice mbed

Fork of blip_analog by Alberto Piganti

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // potenciometro controla la matriz 
00002 // y buzzer al mismo tiempo envia por 
00003 // el puerto serie
00004 
00005 #include "mbed.h"
00006 #include "neopixel.h"
00007 #include "USBSerial.h"
00008 
00009 // Matrix led output pin
00010 #define MATRIX_PIN P0_9
00011 #define NLEDS 25
00012 
00013 
00014 AnalogIn   ain(P0_22);
00015 
00016 unsigned int counter = 0;   
00017 USBSerial serial;
00018 
00019 neopixel::Pixel buffer[NLEDS];
00020 PwmOut speaker(P0_8);
00021 
00022 
00023 void setPixel(uint32_t posicion, uint8_t red, uint8_t green, uint8_t blue) {
00024   buffer[posicion].red=red;
00025   buffer[posicion].green=green;
00026   buffer[posicion].blue=blue;
00027 }
00028 
00029 
00030 int main()
00031 {
00032     // Turn off miniblip buzzer
00033     speaker=0.0;
00034 
00035     serial.printf("Hello world!\n");
00036     DigitalIn(MATRIX_PIN, PullDown);
00037         
00038     while(true) {   
00039         float pot = ain.read()*24;
00040         //serial.printf("mini blip is alive for %i seconds.\n", counter);
00041         serial.printf("Pot: %f\n", pot);
00042         counter++;  
00043     
00044         neopixel::PixelArray array(MATRIX_PIN);
00045         
00046         for(int i=0;i<NLEDS;i++) {
00047             setPixel(i, 0, 0, 0);
00048         }
00049         
00050         if (pot >= 100) pot =100;
00051         setPixel(pot, 0, 20, 0);
00052         
00053         /*
00054         float note=200*(pot);
00055         speaker.period(1.0/note);           
00056         speaker = 50.0;
00057         */
00058         array.update(buffer, NLEDS);
00059         wait_ms(10);    
00060 
00061     }
00062     
00063     //
00064 //    // Create a temporary DigitalIn so we can configure the pull-down resistor.
00065 //    DigitalIn(DATA_PIN, PullDown);
00066 //
00067 //    // The pixel array control class.
00068 //    neopixel::PixelArray array(DATA_PIN);
00069 //
00070 //    uint32_t offset = 0;
00071 //    uint32_t i = 1;
00072 //    while (1) {
00073 //        array.update(generate, 64, offset++);
00074 //        
00075 //        //Play Sound
00076 //        float note=500+(i*100);
00077 //        speaker.period(1.0/note);           
00078 //        //speaker = float(i)/50.0;
00079 //        
00080 //        i++;
00081 //        if (i>10) i=1;
00082 //        // Rainbow delay
00083 //        wait_ms(100);
00084 //    }
00085 }
00086