/*in this code, we are adding a button to the previous project to create two modes
the button acts as a toggle, when it is pressed the texts in led matrix starts moving in opposite directions
*/
/*we have created all the byte arrays of neccerassary alphabets and also the pre and post form of those alphabets*/
/* for moving texts from right to left first we give the pre form follwed by normal form then post form
for moving text from left ro right we give post form, follwed by normal form and then pre form*/
// we have two different functions stringseperator 1 for moving left and string seperator 2 for moving right
#include <EEPROM.h>
char aNumber[] = {' '};
int n;
int count;
char letter[] = {' '};
String letter1[] = {" "};
int i;
const unsigned int MAX_MESSAGE_LENGTH = 50;
unsigned long tim=0;
unsigned long button_time = 0;
unsigned long last_button_time = 0;
bool buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int startPressed = 0; // the moment the button was pressed
int endPressed = 0; // the moment the button was released
int holdTime = 0; // how long the button was hold
int idleTime = 0;
const int buttonPin = 0;
static const int ButtonPin = 1; // switch pin
int buttonStatePrevious = LOW; // previousstate of the switch
unsigned long minButtonLongPressDuration = 3000; // Time we wait before we see the press as a long press
unsigned long buttonLongPressMillis; // Time in ms when we the button was pressed
bool buttonStateLongPress = false; // True if it is a long press
const int intervalButton = 50; // Time between two readings of the button state
unsigned long previousButtonMillis; // Timestamp of the latest reading
unsigned long buttonPressDuration; // Time the button is pressed in ms
//// GENERAL ////
int ScrollingMode = 1;
unsigned long currentMillis;
int button_switch = 18; // external interrupt pin
#define switched true // value if the button switch has been pressed
#define triggered true // controls interrupt handler
#define interrupt_trigger_type RISING // interrupt triggered on a RISING input
#define debounce 2000 // time to wait in milli secs
volatile bool interrupt_process_status = {
!triggered // start with no switch press pending, ie false (!triggered)
};
bool initialisation_complete = false; // inhibit any interrupts until initialisation is complete
//
// ISR for handling interrupt triggers arising from associated button switch
//
void button_interrupt_handler()
{
if (initialisation_complete == true)
{ // all variables are initialised so we are okay to continue to process this interrupt
if (interrupt_process_status == !triggered) {
// new interrupt so okay start a new button read process -
// now need to wait for button release plus debounce period to elapse
// this will be done in the button_read function
if (digitalRead(button_switch) == HIGH) {
// button pressed, so we can start the read on/off + debounce cycle wich will
// be completed by the button_read() function.
interrupt_process_status = triggered; // keep this ISR 'quiet' until button read fully completed
}
}
}
} // end of button_interrupt_handler
bool read_button() {
int button_reading;
// static variables because we need to retain old values between function calls
static bool switching_pending = false;
static long int elapse_timer;
if (interrupt_process_status == triggered) {
// interrupt has been raised on this button so now need to complete
// the button read process, ie wait until it has been released
// and debounce time elapsed
button_reading = digitalRead(button_switch);
if (button_reading == HIGH) {
// switch is pressed, so start/restart wait for button relealse, plus end of debounce process
switching_pending = true;
elapse_timer = millis(); // start elapse timing for debounce checking
}
if (switching_pending && button_reading == LOW) {
// switch was pressed, now released, so check if debounce time elapsed
if (millis() - elapse_timer >= debounce) {
// dounce time elapsed, so switch press cycle complete
switching_pending = false; // reset for next button press interrupt cycle
interrupt_process_status = !triggered;
if(ScrollingMode == 1){
ScrollingMode = 2;
}
else if (ScrollingMode == 2){
ScrollingMode = 1;
}
Serial.println(ScrollingMode);
Toggle(); // reopen ISR for business now button on/off/debounce cycle complete
return switched; // advise that switch has been pressed
}
}
}
return !switched; // either no press request or debounce period not elapsed
} // end of read_button function
void Toggle(){
switch (ScrollingMode){
case 1:
StringSeparator1();
Serial.println("Running Scrolling Mode 1");
break;
case 2:
StringSeparator2();
Serial.println("Running Scrolling Mode 2");
break;
default:
StringSeparator1();
Serial.println("Running something else");
break;
}
}
byte A[] = {
B00111100,
B01000010,
B01000010,
B01111110,
B01000010,
B01000010,
B01000010,
B01000010};
byte K[] = {
B01000010,
B01000100,
B01001000,
B01110000,
B01001000,
B01000100,
B01000010,
B01000001};
byte D[] = {
B11111000,
B10000010,
B10000010,
B10000010,
B10000010,
B10000010,
B10000100,
B11111000};
byte E[] = {
B11111111,
B10000000,
B10000000,
B10000000,
B11111111,
B10000000,
B10000000,
B11111111};
byte F[] = {
B11111111,
B10000000,
B10000000,
B10000000,
B11111111,
B10000000,
B10000000,
B10000000};
byte L[] = {
B10000000,
B10000000,
B10000000,
B10000000,
B10000000,
B10000000,
B10000000,
B11111111};
byte B[] = {
B00000000,
B11111100,
B10000010,
B10000010,
B11111100,
B10000010,
B10000010,
B11111100};
byte R[] = {
B00000000,
B11111100,
B10000010,
B10000010,
B11111100,
B10000010,
B10000010,
B10000010};
byte I[] = {
B11111111,
B00010000,
B00010000,
B00010000,
B00010000,
B00010000,
B00010000,
B11111110};
byte M[] = {
B10000001,
B11000011,
B10100101,
B10011001,
B10000001,
B10000001,
B10000001,
B10000001};
byte N[] = {
B10000001,
B11000001,
B10100001,
B10010001,
B10001001,
B10000101,
B10000011,
B10000001};
byte O[] = {
B01111110,
B10000001,
B10000001,
B10000001,
B10000001,
B10000001,
B10000001,
B01111110};
byte P[] = {
B11111110,
B10000001,
B10000001,
B10000001,
B11111110,
B10000000,
B10000000,
B10000000};
byte Q[] = {
B01111100,
B10000010,
B10000010,
B10000010,
B10000010,
B10001010,
B10000100,
B01111010};
byte V[] = {
B10000001,
B10000001,
B10000001,
B10000001,
B10000001,
B10000001,
B10000001,
B01111110};
byte U[] = {
B10000001,
B10000001,
B10000001,
B10000001,
B10000001,
B10000001,
B10000001,
B11111111};
byte W[] = {
B10000001,
B10000001,
B10000001,
B10000001,
B10011001,
B10100101,
B11000011,
B10000001};
byte Y[] = {
B10000001,
B10000001,
B10000001,
B11111111,
B00011000,
B00011000,
B00011000,
B00011000};
byte G[] = {
B00000000,
B11111110,
B10000010,
B10000000,
B10000000,
B10001110,
B10000010,
B11111110};
byte H[] = {
B00000000,
B10000010,
B10000010,
B10000010,
B11111110,
B10000010,
B10000010,
B10000010};
byte T[] = {
B00000000,
B11111110,
B00010000,
B00010000,
B00010000,
B00010000,
B00010000,
B00010000};
byte Z[] = {
B11111111,
B00000010,
B00000100,
B00001000,
B00010000,
B00100000,
B01000000,
B11111111};
byte J[] = {
B11111111,
B00010000,
B00010000,
B00010000,
B00010000,
B10010000,
B10010000,
B01100000};
byte C[] = {
B00000000,
B01111100,
B10000010,
B10000000,
B10000000,
B10000000,
B10000010,
B01111100};
byte S[] = {
B01111110,
B10000001,
B10000000,
B01111110,
B00000001,
B10000001,
B01111110,
B00000000};
byte SA[] = {
B11100011,
B00010100,
B00000100,
B11100111,
B00010100,
B00010100,
B11100100,
B00000100};
byte AJ[] = {
B11001111,
B00100001,
B00100001,
B11100001,
B00100001,
B00101001,
B00101001,
B00100110};
byte JI[] = {
B11111111,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00001111};
byte ID[] = {
B11111111,
B00001000,
B00001000,
B00001000,
B00001000,
B00001000,
B00001000,
B11101111};
byte ZA[] = {
B11110011,
B00100100,
B01000100,
B10000111,
B00000100,
B00000100,
B00000100,
B11110100};
byte AD[] = {
B11001111,
B00101000,
B00101000,
B11101000,
B00101000,
B00101000,
B00101000,
B00101111};
byte DI[] = {
B10001111,
B00100001,
B00100001,
B00100001,
B00100001,
B00100001,
B01000001,
B10001111};
byte preA[] = {B00001111,B00010000,B00010000,B00010000,B00011111,B00010000,B00010000,B00010000};
byte postA[] = {B11100000,B00010000,B00010000,B00010000,B11110000,B00010000,B00010000,B00010000};
byte preB[] = {B00000000,B00011110,B00010001,B00010001,B00011110,B00010001,B00010001,B00011110};
byte postB[] = {B00000000,B11110000,B10001000,B10001000,B11110000,B10001000,B10001000,B11110000};
byte preC[] = {B00000000,B00001111,B00010000,B00010000,B00010000,B00010000,B00010000,B00001111};
byte postC[] = {B00000000,B11110000,B00001000,B00000000,B00000000,B00000000,B00001000,B11110000};
byte preD[] = {B00011111,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00011111};
byte postD[] = {B11110000,B00001000,B00001000,B00001000,B00001000,B00001000,B00001000,B11110000};
byte preE[] = {B00011111,B00010000,B00010000,B00010000,B00011111,B00010000,B00010000,B00011111};
byte postE[] = {B11110000,B00000000,B00000000,B00000000,B11110000,B00000000,B00000000,B11110000};
byte preF[] = {B00011111,B00010000,B00010000,B00010000,B00011111,B00010000,B00010000,B00010000};
byte postF[] = {B11110000,B00000000,B00000000,B00000000,B00000000,B11110000,B00000000,B00000000};
byte preG[] = {B00000000,B00011111,B00010000,B00010000,B00010000,B00010000,B00010000,B00011111};
byte postG[] = {B00000000,B11110000,B00010000,B00000000,B00000000,B01110000,B00010000,B11110000};
byte preH[] = {B00000000,B00010000,B00010000,B00010000,B00011111,B00010000,B00010000,B00010000};
byte postH[] = {B00000000,B00010000,B00010000,B00010000,B11110000,B00010000,B00010000,B00010000};
byte preI[] = {B00001111,B00000001,B00000001,B00000001,B00000001,B00000001,B00000001,B00001111};
byte postI[] = {B11110000,B10000000,B10000000,B10000000,B10000000,B10000000,B10000000,B11110000};
byte preJ[] = {B00001111,B00000001,B00000001,B00000001,B00000001,B00001001,B00001001,B00000110};
byte postJ[] = {B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};
byte preK[] = {B00010000,B00010000,B00010001,B00011110,B00010001,B00010000,B00010000,B00010000};
byte postK[] = {B01000000,B10000000,B00000000,B00000000,B00000000,B10000000,B01000000,B00100000};
byte preL[] = {B00001000,B00001000,B00001000,B00001000,B00001000,B00001000,B00001000,B00001111};
byte postL[] = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11110000};
byte preM[] = {B00001000,B00001100,B00001010,B00001001,B00001000,B00001000,B00001000,B00001000};
byte postM[] = {B00010000,B00110000,B01010000,B10010000,B00010000,B00010000,B00010000,B00010000};
byte preN[] = {B00001000,B00001100,B00001010,B00001001,B00001000,B00001000,B00001000,B00001000};
byte postN[] = {B00010000,B00010000,B00010000,B00010000,B10010000,B01010000,B00110000,B00010000};
byte preO[] = {B00000111,B00001000,B00001000,B00001000,B00001000,B00001000,B00001000,B00000111};
byte postO[] = {B11100000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B11100000};
byte preP[] = {B00001111,B00001000,B00001000,B00001000,B00001111,B00001000,B00001000,B00001000};
byte postP[] = {B11100000,B00010000,B00010000,B00010000,B11100000,B00000000,B00000000,B00000000};
byte preQ[] = {B00000111,B00001000,B00001000,B00001000,B00001000,B00001000,B00001000,B00000111};
byte postQ[] = {B11000000,B00100000,B00100000,B00100000,B00100000,B10100000,B01000000,B10100000};
byte preR[] = {B00000000,B00001111,B00001000,B00001000,B00001111,B00001000,B00001000,B00001000};
byte postR[] = {B00000000,B11000000,B00100000,B00100000,B11000000,B00100000,B00100000,B00100000};
byte preS[] = {B00000111,B00001000,B00001000,B00000111,B00000000,B00000000,B00000111,B00000000};
byte postS[] = {B11100000,B00000000,B00000000,B11100000,B00010000,B00010000,B11100000,B00000000};
byte preT[] = {B00000000,B00001111,B00000001,B00000001,B00000001,B00000001,B00000001,B00000001};
byte postT[] = {B00000000,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};
byte preU[] = {B00001000,B00001000,B00001000,B00001000,B00001000,B00001000,B00001000,B00001111};
byte postU[] = {B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B11110000};
byte preV[] = {B00001000,B00001000,B00001000,B00001000,B00001000,B00001000,B00001000,B00000111};
byte postV[] = {B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B11100000};
byte preW[] = {B00001000,B00001000,B00001000,B00001000,B00001001,B00001010,B00001100,B00001000};
byte postW[] = {B00010000,B00010000,B00010000,B00010000,B10010000,B01010000,B00110000,B00010000};
byte preX[] = {B00001000,B00000100,B00000010,B00000001,B00000001,B00000010,B00000100,B00001000};
byte postX[] = {B00010000,B00100000,B01000000,B10000000,B10000000,B01000000,B00100000,B00010000};
byte preY[] = {B00001000,B00001000,B00001000,B00001111,B00000001,B00000001,B00000001,B00000001};
byte postY[] = {B00010000,B00010000,B00010000,B11110000,B10000000,B10000000,B10000000,B10000000};
byte preZ[] = {B00001111,B00000000,B00000000,B00000000,B00000001,B00000010,B00000100,B00001111};
byte postZ[] = {B11110000,B00100000,B01000000,B10000000,B00000000,B00000000,B00000000,B11110000};
byte X[] = {B10000001,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B10000001};
byte one[] = {B00010000,B00110000,B01010000,B00010000,B00010000,B00010000,B00010000,B11111110};
byte two[] = {B01111100,B01000100,B00000100,B00000100,B01111100,B01000000,B01000000,B01111100};
byte three[] = {B01111100,B01000100,B00000100,B00000100,B00111100,B00000100,B01000100,B01111100};
byte four[] = {B01000100,B01000100,B01000100,B01000100,B01111100,B00000100,B00000100,B00000100};
byte five[] = {B01111100,B01000000,B01000000,B01111000,B00000100,B00000100,B00000100,B01111000};
byte six[] = {B01111100,B01000000,B01000000,B01111000,B01000100,B01000100,B01000100,B00111000};
byte seven[] = {B01111110,B00000010,B00000010,B00000010,B00000010,B00000010,B00000010,B00000010};
byte eight[] = {B00111100,B01000010,B01000010,B01000010,B00111100,B01000010,B01000010,B00111100};
byte nine[] = {B00111100,B01000010,B01000010,B01000010,B00111110,B00000010,B00000010,B00000010};
byte zero[] = {B01111110,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B01111110};
byte space[] = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};
byte buffer[10];
const int rowPins[] = { 2, 3, 4, 5, 6, 7, 8, 9};
const int columnPins[] = { A3, A2, A1, A0, 13,12, 11, 10};
char text[]= "HowToMechatronics.com ";
void setup() {
Serial.begin(9600);
pinMode(button_switch, INPUT);
attachInterrupt(digitalPinToInterrupt(button_switch),
button_interrupt_handler,
interrupt_trigger_type);
initialisation_complete = true;
Serial.println(' ');
for (int i = 0; i < 8; i++)
{
pinMode(rowPins[i], OUTPUT); // make all the LED pins outputs
pinMode(columnPins[i], OUTPUT);
digitalWrite(columnPins[i], HIGH); // disconnect column pins from Ground
}
}
void loop()
{
//int Delay = 800 ;
currentMillis = millis();
Toggle();
StringInputTest2();
}
void show( byte * image, unsigned long duration)
{
unsigned long start = millis();
while (start + duration > millis())
{
for(int row = 0; row < 8; row++)
{
digitalWrite(rowPins[row], HIGH); // connect row to +5 volts
for(int column = 0; column < 8; column++)
{
boolean pixel = bitRead(image[row],column);
if(pixel == 1)
{
digitalWrite(columnPins[column], LOW); // connect column to Gnd
}
delayMicroseconds(300); // a small delay for each LED
digitalWrite(columnPins[column], HIGH); // disconnect column from Gnd
}
digitalWrite(rowPins[row], LOW); // disconnect LEDs
}
}
}
void StringInput() {
//char string[32];
char byteRead;
int availableBytes = Serial.available();
for (int i = 0; i < availableBytes; i++)
{
//aNumber[i] = Serial.readString();
}
StringSeparator();
}
void StringInputTest2() {
while (Serial.available() > 0)
{
//Create a place to hold the incoming message
static char message[MAX_MESSAGE_LENGTH];
static unsigned int message_pos = 0;
//Read the next available byte in the serial receive buffer
char inByte = Serial.read();
//Message coming in (check not terminating character) and guard for over message size
if ( inByte != '\n' && (message_pos < MAX_MESSAGE_LENGTH - 1) )
{
//Add the incoming byte to our message
message[message_pos] = inByte;
aNumber[message_pos] = inByte;
EEPROM.write(message_pos, aNumber[message_pos]);
message_pos++;
}
//Full message received...
else
{
//Add null character to string
message[message_pos] = '\0';
//Print the message (or do other things)
Serial.println(message);
n = strlen(message);
//updateState();
Toggle();
//readButtonState();
if (read_button() == switched) {
// button on/off cycle now complete, so flip LED between HIGH and LOW
//NumberRand();
// !switched;
}
//Reset for the next message
message_pos = 0;
}
}
}
void StringSeparator() {
for (int x = 0; x < n; x++)
{
//Serial.println(aNumber[x]);
letter[x] = aNumber[x];
//letter[x] = EEPROM.read(0,message[message_pos]);
switch (letter[x]) {
case 'Z':
case 'z':
Serial.println("Z");
show(Z, 1000);
break;
case 'A':
case 'a':
Serial.println("A");
show(A, 1000);
break;
case 'B':
case 'b':
Serial.println("B");
show(B, 1000);
break;
case 'C':
case 'c':
Serial.println("C");
show(C, 1000);
break;
case 'D':
case 'd':
Serial.println("D");
show(D, 1000);
break;
case 'E':
case 'e':
Serial.println("E");
show(E,1000);
break;
case 'F':
case 'f':
Serial.println("F");
show(F,1000);
break;
case 'G':
case 'g':
Serial.println("G");
show(G, 1000);
break;
case 'H':
case 'h':
Serial.println("H");
show(H, 1000);
break;
case 'I':
case 'i':
Serial.println("I");
show(I, 1000);
break;
case 'J':
case 'j':
Serial.println("J");
show(J, 1000);
break;
case 'K':
case 'k':
Serial.println("K");
show(K,1000);
break;
case 'L':
case 'l':
Serial.println("L");
show(L,1000);
break;
case 'M':
case 'm':
Serial.println("M");
show(M,1000);
break;
case 'N':
case 'n':
Serial.println("N");
show(N,1000);
break;
case 'O':
case 'o':
Serial.println("O");
show(O,1000);
break;
case 'P':
case 'p':
Serial.println("P");
show(P,1000);
break;
case 'Q':
case 'q':
Serial.println("Q");
show(Q,1000);
break;
case 'R':
case 'r':
Serial.println("R");
show(R,1000);
break;
case 'S':
case 's':
Serial.println("S");
show(S, 1000);
break;
case 'T':
case 't':
Serial.println("T");
show(T, 1000);
break;
case 'U':
case 'u':
Serial.println("U");
show(U,1000);
break;
case 'V':
case 'v':
Serial.println("V");
show(V,1000);
break;
case 'W':
case 'w':
Serial.println("W");
show(W,1000);
break;
case 'X':
case 'x':
Serial.println("X");
show(X, 1000);
break;
case 'Y':
case 'y':
Serial.println("Y");
show(Y,1000);
break;
case '1':
show(one,1000);
break;
case '2':
show(two,1000);
break;
case '3':
show(three,1000);
break;
case '4':
show(four,1000);
break;
case '5':
show(five,1000);
break;
case '6':
show(six,1000);
break;
case '7':
show(seven,1000);
break;
case '8':
show(eight,1000);
break;
case '9':
show(nine,1000);
break;
case '0':
show(zero,1000);
break;
case ' ':
show(space,1000);
default:
Serial.println("Just a test");
break;
}
}
}
void StringSeparator1() {
for (int x = 0; x < n; x++)
{
//Serial.println(aNumber[x]);
letter[x] = EEPROM.read(x);
//letter[x] = EEPROM.read(0,message[message_pos]);
switch (letter[x]) {
case 'Z':
case 'z':
Serial.println("Z");
show(preZ,1000);
show(Z, 1000);
show(postZ,1000);
break;
case 'A':
case 'a':
Serial.println("A");
show(preA,1000);
show(A, 1000);
show(postA,1000);
break;
case 'B':
case 'b':
Serial.println("B");
show(preB,1000);
show(B, 1000);
show(postB,1000);
break;
case 'C':
case 'c':
Serial.println("C");
show(preC,1000);
show(C, 1000);
show(postC,1000);
break;
case 'D':
case 'd':
Serial.println("D");
show(preD,1000);
show(D, 1000);
show(postD,1000);
break;
case 'E':
case 'e':
Serial.println("E");
show(preE,1000);
show(E, 1000);
show(postE,1000);
break;
case 'F':
case 'f':
Serial.println("F");
show(preF,1000);
show(F, 1000);
show(postF,1000);
break;
case 'G':
case 'g':
Serial.println("G");
show(preG,1000);
show(G, 1000);
show(postG,1000);
break;
case 'H':
case 'h':
Serial.println("H");
show(preH,1000);
show(H, 1000);
show(postH,1000);
break;
case 'I':
case 'i':
Serial.println("I");
show(preI,1000);
show(I, 1000);
show(postI,1000);
break;
case 'J':
case 'j':
Serial.println("J");
show(preJ,1000);
show(J, 1000);
show(postJ,1000);
break;
case 'K':
case 'k':
Serial.println("K");
show(preK,1000);
show(K, 1000);
show(postK,1000);
break;
case 'L':
case 'l':
Serial.println("L");
show(preL,1000);
show(L, 1000);
show(postL,1000);
break;
case 'M':
case 'm':
Serial.println("M");
show(preM,1000);
show(M, 1000);
show(postM,1000);
break;
case 'N':
case 'n':
Serial.println("N");
show(preN,1000);
show(N, 1000);
show(postN,1000);
break;
case 'O':
case 'o':
Serial.println("O");
show(preO,1000);
show(O, 1000);
show(postO,1000);
break;
case 'P':
case 'p':
Serial.println("P");
show(preP,1000);
show(P, 1000);
show(postP,1000);
break;
case 'Q':
case 'q':
Serial.println("Q");
show(preQ,1000);
show(Q, 1000);
show(postQ,1000);
break;
case 'R':
case 'r':
Serial.println("R");
show(preR,1000);
show(R, 1000);
show(postR,1000);
break;
case 'S':
case 's':
Serial.println("S");
show(preS,1000);
show(S, 1000);
show(postS,1000);
break;
case 'T':
case 't':
Serial.println("T");
show(preT,1000);
show(T, 1000);
show(postT,1000);
break;
case 'U':
case 'u':
Serial.println("U");
show(preU,1000);
show(U, 1000);
show(postU,1000);
break;
case 'V':
case 'v':
Serial.println("V");
show(preV,1000);
show(V, 1000);
show(postV,1000);
break;
case 'W':
case 'w':
Serial.println("W");
show(preW,1000);
show(W, 1000);
show(postW,1000);
break;
case 'X':
case 'x':
Serial.println("X");
show(preX,1000);
show(X, 1000);
show(postX,1000);
break;
case 'Y':
case 'y':
Serial.println("Y");
show(preY,1000);
show(Y, 1000);
show(postY,1000);
break;
case '1':
show(one,1000);
break;
case '2':
show(two,1000);
break;
case '3':
show(three,1000);
break;
case '4':
show(four,1000);
break;
case '5':
show(five,1000);
break;
case '6':
show(six,1000);
break;
case '7':
show(seven,1000);
break;
case '8':
show(eight,1000);
break;
case '9':
show(nine,1000);
break;
case '0':
show(zero,1000);
break;
case ' ':
show(space,1000);
default:
Serial.println("Just a test");
break;
}
}
}
void StringSeparator2() {
for (int x = n; x > -1; x--)
{
//Serial.println(aNumber[x]);
letter[x] = EEPROM.read(x);
//letter[x] = EEPROM.read(0,message[message_pos]);
switch (letter[x]) {
case 'Z':
case 'z':
Serial.println("Z");
show(postZ,1000);
show(Z, 1000);
show(preZ,1000);
break;
case 'A':
case 'a':
Serial.println("A");
show(postA,1000);
show(A, 1000);
show(preA,1000);
break;
case 'B':
case 'b':
Serial.println("B");
show(postB,1000);
show(B, 1000);
show(preB,1000);
break;
case 'C':
case 'c':
Serial.println("C");
show(postC,1000);
show(C, 1000);
show(preC,1000);
break;
case 'D':
case 'd':
Serial.println("D");
show(postD,1000);
show(D, 1000);
show(preD,1000);
break;
case 'E':
case 'e':
Serial.println("E");
show(postE,1000);
show(E, 1000);
show(preE,1000);
break;
case 'F':
case 'f':
Serial.println("F");
show(postF,1000);
show(F, 1000);
show(preF,1000);
break;
case 'G':
case 'g':
Serial.println("G");
show(postG,1000);
show(G, 1000);
show(preG,1000);
break;
case 'H':
case 'h':
Serial.println("H");
show(postH,1000);
show(H, 1000);
show(preH,1000);
break;
case 'I':
case 'i':
Serial.println("I");
show(postI,1000);
show(I, 1000);
show(preI,1000);
break;
case 'J':
case 'j':
Serial.println("J");
show(postJ,1000);
show(J, 1000);
show(preJ,1000);
break;
case 'K':
case 'k':
Serial.println("K");
show(postK,1000);
show(K, 1000);
show(preK,1000);
break;
case 'L':
case 'l':
Serial.println("L");
show(postL,1000);
show(L, 1000);
show(preL,1000);
break;
case 'M':
case 'm':
Serial.println("M");
show(postM,1000);
show(M, 1000);
show(preM,1000);
break;
case 'N':
case 'n':
Serial.println("N");
show(postN,1000);
show(N, 1000);
show(preN,1000);
break;
case 'O':
case 'o':
Serial.println("O");
show(postO,1000);
show(O, 1000);
show(preO,1000);
break;
case 'P':
case 'p':
Serial.println("P");
show(postP,1000);
show(P, 1000);
show(preP,1000);
break;
case 'Q':
case 'q':
Serial.println("Q");
show(postQ,1000);
show(Q, 1000);
show(preQ,1000);
break;
case 'R':
case 'r':
Serial.println("R");
show(postR,1000);
show(R, 1000);
show(preR,1000);
break;
case 'S':
case 's':
Serial.println("S");
show(postS,1000);
show(S, 1000);
show(preS,1000);
break;
case 'T':
case 't':
Serial.println("T");
show(postT,1000);
show(T, 1000);
show(preT,1000);
break;
case 'U':
case 'u':
Serial.println("U");
show(postU,1000);
show(U, 1000);
show(preU,1000);
break;
case 'V':
case 'v':
Serial.println("V");
show(postV,1000);
show(V, 1000);
show(preV,1000);
break;
case 'W':
case 'w':
Serial.println("W");
show(postW,1000);
show(W, 1000);
show(preW,1000);
break;
case 'X':
case 'x':
Serial.println("X");
show(postX,1000);
show(X, 1000);
show(preX,1000);
break;
case 'Y':
case 'y':
Serial.println("Y");
show(postY,1000);
show(Y, 1000);
show(preY,1000);
break;
case '1':
show(one,1000);
break;
case '2':
show(two,1000);
break;
case '3':
show(three,1000);
break;
case '4':
show(four,1000);
break;
case '5':
show(five,1000);
break;
case '6':
show(six,1000);
break;
case '7':
show(seven,1000);
break;
case '8':
show(eight,1000);
break;
case '9':
show(nine,1000);
break;
case '0':
show(zero,1000);
break;
case ' ':
show(space,1000);
default:
Serial.println("Just a test");
break;
}
}
}
void updateState() {
// the button has been just pressed
if (buttonState == LOW) {
startPressed = millis();
idleTime = startPressed - endPressed;
if (idleTime >= 500 && idleTime < 1000) {
Serial.println("Button was idle for half a second");
StringSeparator1();
}
if (idleTime >= 1000) {
Serial.println("Button was idle for one second or more");
StringSeparator1();
}
// the button has been just released
} else {
endPressed = millis();
holdTime = endPressed - startPressed;
if (holdTime >= 500 && holdTime < 1000) {
Serial.println("Button was held for half a second");
}
if (holdTime >= 1000) {
Serial.println("Button was held for one second or more");
StringSeparator2();
}
if (holdTime >= 2000) {
Serial.println("Button was held for two second or more");
StringSeparator1();
}
}
}
void readButtonState() {
// If the difference in time between the previous reading is larger than intervalButton
if(currentMillis - previousButtonMillis > intervalButton) {
// Read the digital value of the button (LOW/HIGH)
int buttonState = digitalRead(ButtonPin);
// If the button has been pushed AND
// If the button wasn't pressed before AND
// IF there was not already a measurement running to determine how long the button has been pressed
if (buttonState == HIGH && buttonStatePrevious == LOW && !buttonStateLongPress) {
buttonLongPressMillis = currentMillis;
buttonStatePrevious = HIGH;
Serial.println("Button pressed");
}
// Calculate how long the button has been pressed
buttonPressDuration = currentMillis - buttonLongPressMillis;
// If the button is pressed AND
// If there is no measurement running to determine how long the button is pressed AND
// If the time the button has been pressed is larger or equal to the time needed for a long press
if (buttonState == HIGH && !buttonStateLongPress && buttonPressDuration >= minButtonLongPressDuration) {
buttonStateLongPress = true;
Serial.println("Button long pressed");
StringSeparator1();
}
// If the button is released AND
// If the button was pressed before
if (buttonState == LOW && buttonStatePrevious == HIGH) {
buttonStatePrevious = LOW;
buttonStateLongPress = false;
Serial.println("Button released");
// If there is no measurement running to determine how long the button was pressed AND
// If the time the button has been pressed is smaller than the minimal time needed for a long press
// Note: The video shows:
// if (!buttonStateLongPress && buttonPressDuration < minButtonLongPressDuration) {
// since buttonStateLongPress is set to FALSE on line 75, !buttonStateLongPress is always TRUE
// and can be removed.
if (buttonPressDuration < minButtonLongPressDuration) {
Serial.println("Button pressed shortly");
StringSeparator2();
}
}
// store the current timestamp in previousButtonMillis
previousButtonMillis = currentMillis;
}
}