Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************************************
- * 16x8 LED Matrix Message for Ham Radio *
- *********************************************************
- **********************************************************/
- //Libraries
- #include <Wire.h>
- #include "Adafruit_LEDBackpack.h"
- #include "Adafruit_GFX.h"
- //Library initialization
- Adafruit_8x16matrix matrix = Adafruit_8x16matrix();
- //Constants
- #define APPLAUSE_ITER 1 //This is the number of times the "applause" message will scroll
- #define DELAY_TIME1 45 //Amount of milliseconds for the delay (on air message)
- #define DELAY_TIME2 60 //Amount of milliseconds for the delay (applause and stand by messages)
- //Pin definitions
- #define buttonPin 2 //The pin used for the button
- //Variables
- int buttonState = 0; //Variable for saving the state of the button, If the button is pressed, the value is 1, if not, it is 0 (button needs a 10kOhm pull down resistor)
- int lastButtonState = 0; //Variable for saving the previous state of the button
- boolean stdByState = false; //Boolean variable for the "stand by" message (can be either true or false, initializes as false)
- void setup() {
- Serial.begin(9600);
- Serial.println("16x8 LED Matrix Test");
- matrix.begin(0x70); // pass in the address
- pinMode(buttonPin, INPUT); //Stablish the pin as an input
- //Moved this part of the code to the setup because if it's always going to be the same, it just needs to be executed one time
- matrix.setBrightness(1);
- matrix.setTextSize(1);
- matrix.setTextWrap(false); // we don't want text to wrap so it scrolls nicely
- matrix.setTextColor(LED_ON);
- matrix.setRotation(1);
- }
- void loop() {
- buttonState = digitalRead(buttonPin); //Read the button value
- if (!buttonState && lastButtonState){ //If button is currently not pressed but the last time it was
- applauseMessage();
- }
- lastButtonState = buttonState; //Save last button value
- if (buttonState) { //if button is pressed, call the on air message function
- onAirMessage();
- }
- else if (stdByState && !buttonState) { //if button has already been pressed but isn't currently
- standByMessage();
- }
- else {
- matrix.clear();
- matrix.writeDisplay();
- }
- }
- void onAirMessage() {
- stdByState = true; //when the button is pressed "stand by" state becomes true
- matrix.blinkRate(0);
- for (int8_t x=16; x>=-56; x--) {
- buttonState = digitalRead(buttonPin); //Read the button value in each iteration of the for loop
- if (buttonState) { //if when inside the for loop the button is still pressed stay on the loop and print on the matrix
- matrix.clear();
- matrix.setCursor(x,0);
- matrix.print("-ON AIR!-");
- matrix.writeDisplay();
- delay(DELAY_TIME1);
- }
- else { //else, if the button is no longer pressed, clear the matrix, exit the loop and call applauseMessage function
- matrix.clear();
- matrix.writeDisplay();
- //applauseMessage();
- break;
- }
- }
- }
- void applauseMessage() {
- matrix.blinkRate(1);
- for (int x=0; x<APPLAUSE_ITER; x++) {
- for (int8_t x=16; x>=-56; x--) {
- buttonState = digitalRead(buttonPin);
- if (!buttonState) {
- matrix.clear();
- matrix.setBrightness(2);
- matrix.setCursor(x,0);
- matrix.print("Applause");
- matrix.writeDisplay();
- delay(DELAY_TIME2);
- }
- else {
- matrix.clear();
- matrix.writeDisplay();
- break;
- }
- }
- if (buttonState) break;
- }
- }
- void standByMessage() {
- matrix.blinkRate(0);
- for (int8_t x=16; x>=-56; x--) {
- buttonState = digitalRead(buttonPin);
- if (!buttonState) { //if button is not pressed stay on loop
- matrix.clear();
- matrix.setBrightness(1);
- matrix.setCursor(x,0);
- matrix.print("-STANDBY-");
- matrix.writeDisplay();
- delay(DELAY_TIME2);
- }
- else { //else, if the button is pressed, clear the matrix and exit the loop
- matrix.clear();
- matrix.writeDisplay();
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement