CÓDIGO EN ARDUINO BLOCKS
BLOG ORIGINAL DEL CÓDIGO
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_LEDBackpack.h>
double i;
Adafruit_8x8matrix ledmatrix_1 =Adafruit_8x8matrix();
double math_random_int(int a,int b) {
if (a > b) {
int c = a;
a = b;
b = c;
}
return (double)random(a,b+1);
}
static const uint8_t PROGMEM ledmatrix_data_sprite_face_happy[] PROGMEM = {B00000000,B01100110,B01100110,B00000000,B00000000,B11000011,B01100110,B00111100};
static const uint8_t PROGMEM ledmatrix_data_sprite_face_sad[] PROGMEM = {B00000000,B01100110,B00100100,B00000000,B00111100,B01100110,B11000011,B10000001};
static const uint8_t PROGMEM ledmatrix_data_sprite_face_angry[] PROGMEM = {B00000000,B01000010,B01100110,B00000000,B00000000,B11111111,B10100101,B11111111};
static const uint8_t PROGMEM ledmatrix_data_sprite_eye_medium[] PROGMEM = {B00000000,B00111100,B01000010,B01011010,B01011010,B01000010,B00111100,B00000000};
static const uint8_t PROGMEM ledmatrix_data_sprite_icon_arrowU[] PROGMEM = {B00011000,B00111100,B01111110,B11111111,B00011000,B00011000,B00011000,B00011000};
static const uint8_t PROGMEM ledmatrix_data_sprite_icon_ray[] PROGMEM = {B10000000,B01000000,B01101000,B00111100,B00111100,B00010110,B00000010,B00000001};
static const uint8_t PROGMEM ledmatrix_data_sprite_icon_star[] PROGMEM = {B00010000,B00010000,B00111000,B11111110,B01111100,B00111000,B01101100,B01000100};
static const uint8_t PROGMEM ledmatrix_data_0[] PROGMEM = {B00000000,B01100110,B10011001,B10000001,B10000001,B01000010,B00100100,B00011000};
static const uint8_t PROGMEM ledmatrix_data_1[] PROGMEM = {B01010101,B00000000,B00100100,B00100100,B10000001,B11000011,B01100110,B00111100};
void dibujar_pixeles() {
ledmatrix_1.clear(); ledmatrix_1.writeDisplay();
for (int count = 0; count < 100; count++) {
ledmatrix_1.drawPixel((math_random_int(0, 7)),(math_random_int(0, 7)),LED_ON); ledmatrix_1.writeDisplay();
delay(20);
}
}
void iconos() {
ledmatrix_1.clear(); ledmatrix_1.drawBitmap(0,0,ledmatrix_data_sprite_face_happy,8,8,LED_ON); ledmatrix_1.writeDisplay();
delay(1000);
ledmatrix_1.clear(); ledmatrix_1.drawBitmap(0,0,ledmatrix_data_sprite_face_sad,8,8,LED_ON); ledmatrix_1.writeDisplay();
delay(1000);
ledmatrix_1.clear(); ledmatrix_1.drawBitmap(0,0,ledmatrix_data_sprite_face_angry,8,8,LED_ON); ledmatrix_1.writeDisplay();
delay(1000);
ledmatrix_1.clear(); ledmatrix_1.drawBitmap(0,0,ledmatrix_data_sprite_eye_medium,8,8,LED_ON); ledmatrix_1.writeDisplay();
delay(1000);
ledmatrix_1.clear(); ledmatrix_1.drawBitmap(0,0,ledmatrix_data_sprite_icon_arrowU,8,8,LED_ON); ledmatrix_1.writeDisplay();
delay(1000);
ledmatrix_1.clear(); ledmatrix_1.drawBitmap(0,0,ledmatrix_data_sprite_icon_ray,8,8,LED_ON); ledmatrix_1.writeDisplay();
delay(1000);
ledmatrix_1.clear(); ledmatrix_1.drawBitmap(0,0,ledmatrix_data_sprite_icon_star,8,8,LED_ON); ledmatrix_1.writeDisplay();
delay(1000);
}
void lineas() {
ledmatrix_1.clear(); ledmatrix_1.writeDisplay();
ledmatrix_1.drawLine(0,0,7,7,LED_ON); ledmatrix_1.writeDisplay();
ledmatrix_1.drawLine(0,7,7,0,LED_ON); ledmatrix_1.writeDisplay();
delay(2000);
}
void cuadrado_creciendo() {
for (i = 0; i <= 7; i=i+1) {
ledmatrix_1.clear(); ledmatrix_1.writeDisplay();
ledmatrix_1.drawRect(0,0,i,i,LED_ON); ledmatrix_1.writeDisplay();
delay(200);
}
}
void imagenes() {
ledmatrix_1.clear(); ledmatrix_1.drawBitmap(0,0,ledmatrix_data_0,8,8,LED_ON); ledmatrix_1.writeDisplay();
delay(2000);
ledmatrix_1.clear(); ledmatrix_1.drawBitmap(0,0,ledmatrix_data_1,8,8,LED_ON); ledmatrix_1.writeDisplay();
delay(2000);
}
void circulo_creciendo() {
for (i = 0; i <= 7; i=i+1) {
ledmatrix_1.clear(); ledmatrix_1.writeDisplay();
ledmatrix_1.drawCircle(4,4,i,LED_ON); ledmatrix_1.writeDisplay();
delay(500);
}
}
void scroll_de_texto() {
for (i = 0; i >= -70; i=i-1) {
ledmatrix_1.clear(); ledmatrix_1.writeDisplay();
ledmatrix_1.setCursor(i,0); ledmatrix_1.print(String("ArduinoBlocks")); ledmatrix_1.writeDisplay();
delay(100);
}
}
void setup()
{
ledmatrix_1.begin(0x70);
ledmatrix_1.setType(0);
ledmatrix_1.setTextWrap(false);
ledmatrix_1.setTextSize(1);
randomSeed(analogRead(0));
ledmatrix_1.clear(); ledmatrix_1.writeDisplay();
}
void loop()
{
dibujar_pixeles();
lineas();
cuadrado_creciendo();
circulo_creciendo();
scroll_de_texto();
iconos();
imagenes();
}
Comentarios
Publicar un comentario