int DATA = 11; //pin 14 on the 75HC595
int LATCH = 10; //pin 12 on the 75HC595
int SHIFT = 12; //pin 11 on the 75HC595
String voice;
int delayValue = 0;
int potPin = 1; //potenciometer number of pin
//How many of the shift registers - change this
#define number_of_74hc595s 4
//do not touch
#define numOfRegisterPins number_of_74hc595s * 8
boolean registers[numOfRegisterPins];
void setup(){
Serial.begin(9600);
pinMode(DATA, OUTPUT);
pinMode(LATCH, OUTPUT);
pinMode(SHIFT, OUTPUT);
}
//set all register pins to LOW
void clearRegisters(){
for(int i = numOfRegisterPins - 1; i >= 0; i--){
registers[i] = LOW;
}
}
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){
digitalWrite(LATCH, LOW);
for(int i = numOfRegisterPins - 1; i >= 0; i--){
digitalWrite(SHIFT, LOW);
int val = registers[i];
digitalWrite(DATA, val);
digitalWrite(SHIFT, HIGH);
}
digitalWrite(LATCH, HIGH);
}
//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
registers[index] = value;
}
void oneByOne() {
clearRegisters();
setRegisterPin(4,HIGH);
for(int i=5; i<=29; i++) {
setRegisterPin(i,HIGH);
writeRegisters();
delay(60);
}
clearRegisters();
setRegisterPin(3,HIGH);
for(int i=5; i<=29; i++) {
setRegisterPin(i,HIGH);
writeRegisters();
delay(60);
}
clearRegisters();
setRegisterPin(2,HIGH);
for(int i=5; i<=29; i++) {
setRegisterPin(i,HIGH);
writeRegisters();
delay(60);
}
clearRegisters();
setRegisterPin(1,HIGH);
for(int i=5; i<=29; i++) {
setRegisterPin(i,HIGH);
writeRegisters();
delay(60);
}
clearRegisters();
setRegisterPin(0,HIGH);
for(int i=5; i<=29; i++) {
setRegisterPin(i,HIGH);
writeRegisters();
delay(60);
}
}
This is example of beggining of my program - only one function, because I have plenty of them and the code is very long.
When I used voice control I started the followin code with different dimensions ofc.
while (Serial.available())
{ //Check if there is an available byte to read
delay(10);
char c = Serial.read(); //Conduct a serial read
if (c == '#') {
break;
} //Exit the loop when the # is detected after the word
voice += c; //Shorthand for voice = voice + c
}
if (voice.length() > 0) {
Serial.println(voice);
if(voice == "*1") {
oneByOne();
}
else if(voice == "*all"){
All();
}
else if(voice == "*fireworks") {
fireWorks();
}
else if(voice == "*border") {
borderAll();
}
else if(voice == "*lines") {
runningLines();
}
else if(voice == "*up and down") {
upAndDown();
}
voice="";
}
Actually if sending can be done from PC (like web based app, or .NET based) and then the information could be send via bluetooth it will be good too. I need to find a way how to send bytes or even better char array, cuz later when I received information I`ll use this code :
/* for receiving char array and lights up led according to IT
char first[] = "100001110011";
for(int i=0; i<=12; i++) {
int value = first[i] - '0';
setRegisterPin(i,value);
writeRegisters();
delay(200);
}
*/