I am a total newbie to Arduino so apologies in advance!
I am trying to setup an Adafruit BicolorMatrix with a pushbutton, the idea is that eventually I will get it linked into my app that I have had developed (I did the design but I got an outside programmer!)
I am trying to replicate Theatre Cue lights, normally wired but I have come up with a wifi system. http://stagecue.eu/?page_id=27
Anyway, for now I am simply trying to get the lights to work via a pushbutton and my limited knowledge doesn't even allow me that functionality after several hours trawling the web!
I would be happy to try this code out with ident icon up first, then scrolling text, then flashing Red whole matrix...
So far so good, but I cant figure out how to then press a button to stop the flashing. (the button would also send a wifi signal back to the iPad at this point).
Once acknowledged, the iPad could send another signal to start a Green matrix display flashing, and again pressing the same button would steady the Red light and send another message back.
I am not asking how to send a message via wifi, great if you know how but just to advance through the stages would be a start.
Code I have managed so far as below. the "for(int i = 0; i < 1; i);" is the only way I have found to have an infinite flash loop.
(didn't save my earlier efforts, now that flash wont work constantly either, HELP!
/***************************************************
This is a library for our I2C LED Backpacks
Designed specifically to work with the Adafruit LED Matrix backpacks
----> Adafruit Mini 0.8 8x8 LED Matrix w/I2C Backpack - Yellow-Green : ID 872 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits
----> Adafruit Mini 8x8 LED Matrix w/I2C Backpack - Yellow : ID 871 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits
----> Adafruit Mini 8x8 LED Matrix w/I2C Backpack - Red : ID 870 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits
These displays use I2C to communicate, 2 pins are required to
interface. There are multiple selectable I2C addresses. For backpacks
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
with 3 Address Select pins: 0x70 thru 0x77
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
const int buttonInput = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int i = 0;
Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();
void setup() {
pinMode(buttonInput, INPUT);
digitalWrite(buttonInput, HIGH);
matrix.begin(0x70); // pass in the address
}
void loop() {
matrix.clear();
matrix.drawRect(0,0, 8,8, LED_GREEN);
matrix.fillRect(2,2, 4,4, LED_YELLOW);
matrix.writeDisplay(); // write the changes we just made to the display
delay(2000);
matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix.setRotation(3);
matrix.setTextSize(0);
matrix.setTextColor(LED_GREEN);
for (int8_t x=7; x>=-36; x--) {
matrix.clear();
matrix.setCursor(x,0);
matrix.print("Cue1");
matrix.writeDisplay();
delay(100);
}
for(int i = 0; i < 1; i); // SHOULD flash the light infinitely till button pressed, DID WORK BUT HAVE MESSED UP SOMEWHERE!!
matrix.fillRect(0,0, 8,8, LED_RED);
matrix.writeDisplay(); // write the changes we just made to the display
delay(200);
matrix.clear();
matrix.writeDisplay(); // write the changes we just made to the display
delay(200);
{
/****************************************************
THIS BIT I CANT GET TO WORK...
// flashes the light infinitely
// 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)
THEN SWITCH TO STATIC STATE
for(int i = 0; i < 1; i);
matrix.clear();
matrix.fillRect(0,0, 8,8, LED_RED);
matrix.writeDisplay(); // write the changes we just made to the display
****************************************************/
{
for(int i = 0; i < 1; i); // flashes the light infinitely till button pressed
matrix.clear();
matrix.fillRect(0,0, 8,8, LED_GREEN);
matrix.writeDisplay(); // write the changes we just made to the display
delay(200);
matrix.clear();
matrix.writeDisplay(); // write the changes we just made to the display
delay(200);
for(int i = 0; i < 1; i); // light stays on solid for approx 30 seconds then the cycle reverts to RED waiting to receive message so that it can flash again.
matrix.clear();
matrix.fillRect(0,0, 8,8, LED_GREEN);
matrix.writeDisplay(); // write the changes we just made to the display
delay(30000);
}
}}