Skip to content

Instantly share code, notes, and snippets.

@blackymetal
Last active August 29, 2015 14:01
Show Gist options
  • Save blackymetal/5c3367f138e4027fae6d to your computer and use it in GitHub Desktop.
Save blackymetal/5c3367f138e4027fae6d to your computer and use it in GitHub Desktop.
Arduino Electronic dice
/***************************************************
Author Arianne Patiño and Ariel Patiño
****************************************************/
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();
static const uint8_t PROGMEM
uno[] = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00010000,
B00000000},
dos[] = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00101000,
B00000000},
tres[] = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00100000,
B00010000,
B00001000},
cuatro[] = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00101000,
B00000000,
B00101000},
cinco[] = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00101000,
B00010000,
B00101000},
seis[] = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00101010,
B00000000,
B00101010},
uno_[] =
{ B00000000,
B00010000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000 },
dos_[] =
{ B00000000,
B00101000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000 },
tres_[] =
{ B00100000,
B00010000,
B00001000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000 },
cuatro_[] =
{ B00101000,
B00000000,
B00101000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000 },
cinco_[] =
{ B00101000,
B00010000,
B00101000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000 },
seis_[] =
{ B00101010,
B00000000,
B00101010,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000 };
const unsigned char *dice_table[] = // change "string_table" name to suit
{
uno,
dos,
tres,
cuatro,
cinco,
seis
};
const unsigned char *dice_table2[] = // change "string_table" name to suit
{
uno_,
dos_,
tres_,
cuatro_,
cinco_,
seis_
};
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
const int buttonPin = 2; // the number of the pushbutton pin
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("TEST");
matrix.begin(0x70); // pass in the address
matrix.drawRect(0,3,8,2, LED_YELLOW);
matrix.writeDisplay();
// Limpia la matriz
matrix.clear();
}
void loop() {
matrix.setRotation(3);
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
matrix.clear();
// put your main code here, to run repeatedly:
int dice1 = random(0, 6);
int dice2 = random(0, 6);
int i;
matrix.drawBitmap(0, 0, dice_table[dice1], 8, 8, LED_RED);
matrix.writeDisplay();
matrix.drawBitmap(0, 0, dice_table2[dice2], 8, 8, LED_RED);
matrix.writeDisplay();
matrix.drawRect(0,3,8,2, LED_YELLOW);
// Lo muestra en la matriz
matrix.writeDisplay();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment