Hi all,
I'm sure ive done this before but cant work out why its not working.
The result it get is :
...
TOTAL: 83
LAST TOTAL :0
TOTAL: 86
LAST TOTAL :0
TOTAL: 89
LAST TOTAL :0
TOTAL: 90
LAST TOTAL :0
...
ie the total isnt getting moved to the last total variable..
// Arduino VW buggy controller v1.1
void setup(){
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(5,INPUT);
pinMode(6,INPUT);
pinMode(7,INPUT);
pinMode(8,INPUT);
Serial.begin(9600);
}
void loop(){
int total;
int lasttotal;
lasttotal=total; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< is this where my problem lies?
total = totalcounter();
Serial.print("TOTAL: ");
Serial.println(total);
Serial.print("LAST TOTAL :");
Serial.println(lasttotal);
delay(1000);
}
int totalcounter(){
int pins = 7;
int i;
int temptotal;
int total;
int currentpin;
int currentval;
total=0;
for(i=0;i<pins;i++){
currentpin = i+2;
currentval = pow(2,i)+0.5;
temptotal = countercheck(currentpin,currentval);
total = temptotal + total;
}
return(total);
}
int countercheck(int cnt, int value){
if(digitalRead(cnt)==0){
return (0);
}
else if(digitalRead(cnt)==1){
return (value);
}
}
Thanks in advance ![]()