Código de iniciación para MiniBlip: LEDs+pulsador+puertoSerie
Dependencies: PixelArray USBDevice mbed
main.cpp
- Committer:
- carlosgs
- Date:
- 2016-01-18
- Revision:
- 0:49f15045d34a
File content as of revision 0:49f15045d34a:
// Programa de Hola mundo // Animación en la matriz de LEDs, recibe input del pulsador, y escribe por el puerto serie // Enlaces útiles: // http://hack-miniblip.github.io/programar.html // https://raw.githubusercontent.com/hack-miniblip/hack-miniblip.github.io/master/Scripts/miniblip_loader.sh // https://github.com/hack-miniblip/hack-miniblip.github.io/blob/master/cookbook.md // http://hack-miniblip.github.io/esquema_minilip_pinout.png #include "mbed.h" #include "neopixel.h" #include "USBSerial.h" // Matrix led output pin #define MATRIX_PIN P0_9 #define NLEDS 25 unsigned int counter = 0; USBSerial serial; DigitalIn pushbutton(P0_23); //Define pushbutton neopixel::Pixel buffer[NLEDS]; neopixel::PixelArray array(MATRIX_PIN); void setPixel(int x, int y, uint8_t red, uint8_t green, uint8_t blue) { if(x < 0 || x > 4 || y < 0 || y > 4) return; int posicion=x+y*5; buffer[posicion].red=red; buffer[posicion].green=green; buffer[posicion].blue=blue; } void updateLEDs() { array.update(buffer, NLEDS); } void clearPixels() { for(int x=0; x<5; x++) for(int y=0; y<5; y++) setPixel(x,y, 0,0,0); } PwmOut speaker(P0_8); int main() { // Apagar el zumbador speaker=0.0; // setPixel(x,y, r,g,b); // valor máximo RGB: 255 // Poner todos los LED en verde gradualmente for(int x=0; x<5; x++) { for(int y=0; y<5; y++) { setPixel(x,y, 0,10,0); updateLEDs(); wait_ms(100); } } clearPixels(); // Poner a 0 la matriz actual // Dibujar un smiley setPixel(4,1, 0,0,20); // ojos setPixel(4,3, 0,0,20); setPixel(1,0, 0,0,20); // boca setPixel(0,1, 0,0,20); setPixel(0,2, 0,0,20); setPixel(0,3, 0,0,20); setPixel(1,4, 0,0,20); while(1) { if (pushbutton) { updateLEDs(); // Se muestra el smiley serial.printf("Hola Mundo! Texto enviado por el puerto serie, a 9600 baudios\r\n"); wait(1); // Espera 1 segundo } } }