hello guys,
i wrote a simple script to see what the problem might be
first i have a serial communication between 2 arduinos : 2 buttons are connected to the first and the second is controlling a 1 digit display, the display is showing numbers from 0 to 6 (0 is the default value)
so when i click the first button, numbers goes from 0 to 6 as long as i keep clicking (+1 every click)
and the when i click the second button is decrease back to 0
the problem is that when i go up and down 8 times, everything stops and i am not able to do it again, untill i re upload the scripts to both arduinos so what is the problem here ?
here is the script of the first arduino which has buttons connected :
//Arduino number 1
int downShift = 2; //Left paddle shift pin 2
int upShift = 3; //Right paddle shift pin 3
int burnout = 5; //Burnout Button pin 5
int neutral = 6; //Neutral Green Button pin 6
int reverse = 7; //Reverse Button pin 7
int limiter = 8; //Pit Limiter Button pin 8
int cam = 9; //Cam grey Button pin 9//pin 4 is the white button
//downShift
boolean lastButton1 = LOW;
boolean currentButton1 = LOW;//upShift
boolean lastButton2 = LOW;
boolean currentButton2 = LOW;//burnout
boolean lastButton4 = LOW;
boolean currentButton4 = LOW;//neutral
boolean lastButton5 = LOW;
boolean currentButton5 = LOW;//reverse
boolean lastButton6 = LOW;
boolean currentButton6 = LOW;//limiter
boolean lastButton7 = LOW;
boolean currentButton7 = LOW;//cam
boolean lastButton8 = LOW;
boolean currentButton8 = LOW;void setup(){
Serial.begin(9600);
for(int i = 2; i<9; i++){
pinMode(i, INPUT);
}}
//debounce function
boolean debounce(boolean last, int button)
{
boolean current = digitalRead(button);
if(last != current)
{
delay(5);
current = digitalRead(button);
}
return current;
}void loop(){
//for the downShift
currentButton1 = debounce(lastButton1, downShift);
if(lastButton1 == LOW && currentButton1 == HIGH)
{
Serial.write("-");
}
lastButton1 = currentButton1;//for the upShift
currentButton2 = debounce(lastButton2, upShift);
if(lastButton2 == LOW && currentButton2 == HIGH)
{
Serial.write("+");
}
lastButton2 = currentButton2;}
this is the second script for the second arduino which has the 7 segment display connected :
//For the 2 digits displays////////////////////////////////////////////////////////////////////
byte datapin = 2;
byte clockpin = 3;
byte latchpin = 4;
byte datapin2 = 7;
byte clockpin2 = 8;
byte latchpin2 = 9;
byte First = 5;
byte Second = 6;
byte Third = 10;
byte Fourth = 11;
int times;
byte segments[14] = {0b11111111, //Blank - 0
0b00101011, //n - 1
0b10000110, //E - 2
0b00000111, //t - 3
0b10101111, //r - 4
0b11001111, //l - 5
0b10000011, //b - 6
0b11000000, //O - 7
0b11100011, //u - 8
0b11010101, //v - 9
0b11000111, //L - 10
0b11001111, //i - 11
0b11101010, //M - 12
0b10001001
};
byte FirstDigit;
byte SecondDigit;
byte ThirdDigit;
byte FourthDigit;
byte FirstD;
byte SecondD;
byte ThirdD;
byte FourthD;
//these pins for the gear number display///////////////////////////////////////////////////////
byte latchPin0 = 15; //latch pin
byte clockPin0 = 16; //clock pin
byte dataPin0 = 14; //data pin
byte gearDisplay = 0;
int gearBox = 0;
byte segments1Digit[7] = {0b00000011, //0 - position 1
0b10011111, //1 - position 2
0b00100101, //2 - position 3
0b00001101, //3 - position 4
0b10011001, //4 - position 5
0b01001001, //5 - position 6
0b01000001, //6 - position 7
};
boolean burnoutOn = false;
boolean neutralOn = false;
boolean reverseOn = false;
boolean limiterOn = false;
boolean camOn = false;
void setup()
{
Serial.begin(9600);
for(int x = 2; x < 20; x++){
pinMode(x, OUTPUT);
}
digitalWrite(Second,HIGH);
digitalWrite(First,HIGH);
digitalWrite(datapin,LOW);
digitalWrite(latchpin,LOW);
digitalWrite(clockpin,LOW);
digitalWrite(Fourth,HIGH);
digitalWrite(Third,HIGH);
digitalWrite(datapin2,LOW);
digitalWrite(latchpin2,LOW);
digitalWrite(clockpin2,LOW);
}
void loop()
{
//Puting Limits for the gear box up and down
if(gearBox > 6){
gearBox = 6;
}else if(gearBox < 0){
gearBox = 0;
}
//Read from Serial port
if(Serial.available() > 0){
int value = Serial.read();
if(value == '+'){
gearBox++;
}
if(value == '-'){
gearBox--;
}
}
gearDisplay = gearBox;
updateShiftRegister();
}
void updateShiftRegister()
{
shiftOut(dataPin0, clockPin0, LSBFIRST, segments1Digit[gearDisplay]);
digitalWrite(latchPin0, LOW);
digitalWrite(latchPin0, HIGH);
}