Go Down

Topic: Arduino speedometer not working for an unknown reason (Read 2 times) previous topic - next topic

danlebarbare

Thank you very much for your help and i'll check that out! I just saw that this is not the last version of my code and in the last one I changed the "or" for something other that I forgot but it still didn't worked. Sorry for my beginer errors...

danlebarbare

#6
Aug 17, 2012, 03:31 am Last Edit: Aug 17, 2012, 03:39 am by danlebarbare Reason: 1
I really thank you for your help but after MANY hours of reading on the internet and MANY modifications to my code its still not working because that I still understand what you said above (I know that I'm a bad programer, i'm a lot better to build than to program and i'm bad I dont completly understand english) after all these hours of reading on the net... Here's what I came up with but its just showing a 0 whili I turn the wheel and then it goes to 8 and it stays like that until I stop turning the wheel (then, it shoes nothing just like I want it to be). BTW in an other program I printed the speed values to my PC and they are negative; any ideas why?  Oh and if someone want to write the program for me, I have no problem with that but I know that you dont really have the time will to do that. THANK YOU ALL FOR YOUR HELP!!!



Code: [Select]

#define  DELAY_START   HIGH   // or low depending on your blink detection logic
#define  DELAY_END   !DELAY_START   // this is the inverse of the above
const int buttonPin = 14;
int buttonState = 0;
long start, duration;
long start2, duration2;
long start1, duration1;
long duration3;
long vitesse;
void setup() {
 pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
}
void loop(){  
duration = 0;
duration2 = 0;
duration3 = 0;
while( digitalRead(buttonPin) != DELAY_START   );
start1 = millis();
while( digitalRead(buttonPin) != DELAY_END   );
duration1 = start1 - millis();
delay(50);
while( digitalRead(buttonPin) != DELAY_START   );
start2 = millis();
while( digitalRead(buttonPin) != DELAY_END   );
duration2 = start2 - millis();
duration3 = duration1 + duration2;
duration = duration3/2;
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);


if (217/duration*3.6 == -0 || -10 || -20 || -30) {
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
 delay(500);
}
else {
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
if (217/duration*3.6 == -1 || -11 || -21 || -31) {
digitalWrite(11, HIGH);
digitalWrite(7, HIGH);
delay(500);
}
else {
digitalWrite(11, LOW);
digitalWrite(7, LOW);
}
if (217/duration*3.6 == -2 || -12 || -22 || -32) {
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
digitalWrite(10, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
delay(500);
}
else {
digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(10, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}
if (217/duration*3.6 == -3 || -13 || -23 || -33) {
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
delay(500);
}
else {
digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
}
if (217/duration*3.6 == -4 || -14 || -24 || -34) {
 digitalWrite(11, HIGH);
 digitalWrite(10, HIGH);
 digitalWrite(13, HIGH);
 digitalWrite(9, HIGH);
 delay(500);
}
else {
 digitalWrite(11, LOW);
 digitalWrite(10, LOW);
 digitalWrite(13, LOW);
 digitalWrite(9, LOW);
}
if (217/duration*3.6 == -5 || -15 || -25 || -35) {
 digitalWrite(12, HIGH);
 digitalWrite(11, HIGH);
 digitalWrite(10, HIGH);
 digitalWrite(9, HIGH);
 digitalWrite(8, HIGH);
 delay(500);
}
else {
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
}
if (217/duration*3.6 == -6 || -16 || -26 || -36) {
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
delay(500);
}
else {
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
}
if (217/duration*3.6 == -7 || -17 || -27 || -37) {
digitalWrite(9, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
delay(500);
}
else {
   digitalWrite(9, LOW);
 digitalWrite(12, LOW);
 digitalWrite(13, LOW);
}
if (217/duration*3.6 == -8 || -18 || -28 || -38) {
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
 delay(500);
}
else {
 digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
if (217/duration*3.6 == -9 || -19 || -29 || -39) {
 digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
 delay(500);
}
else {
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}

PeterH


Code: [Select]

if (217/duration*3.6 == -0 || -10 || -20 || -30) {



This is utter nonsense, as has already been explained.
I only provide help via the forum - please do not contact me for private consultancy.

PaulS

Quote
This is utter nonsense, as has already been explained.

I think that should be:
This is STILL utter nonsense, as has already been explained.

danlebarbare

#9
Aug 20, 2012, 07:38 pm Last Edit: Aug 20, 2012, 07:41 pm by danlebarbare Reason: 1
First, THANK YOU VERY MUCH GUYS FOR YOUR HELP!!!I know guys that you already said to me that this part of the code ( || ) would not work but I dont see why... Anyways after reading even more on the forum with my brother (wich programs JAVA and things like that) we came up with this but it only shows 0 and I tested the speedometer part by printing in the values and they looked ok...

Code: [Select]
#define  DELAY_START   HIGH   // or low depending on your blink detection logic
#define  DELAY_END   !DELAY_START   // this is the inverse of the above
const int buttonPin = 14;
int buttonState = 0;
long start, duration;
long start2, duration2;
long start1, duration1;
long duration3;
long vitesse;
int remainder;
void setup() {
 pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
}
void loop(){
while( digitalRead(buttonPin) != DELAY_START   );
start1 = millis();
while( digitalRead(buttonPin) != DELAY_END   );
duration1 = start1 - millis();
delay(50);
while( digitalRead(buttonPin) != DELAY_START   );
start2 = millis();
while( digitalRead(buttonPin) != DELAY_END   );
duration2 = start2 - millis();
duration3 = duration1 + duration2;
duration = duration3/2;
vitesse = (217/(duration)*3.6);
remainder = vitesse % 10;
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);

if (remainder == 1) {
digitalWrite(1, HIGH);
digitalWrite(4, HIGH);
}

else if (remainder == 2) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(0, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
}

else if (remainder == 3) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(0, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
}

else if (remainder == 4) {
digitalWrite(1, HIGH);
digitalWrite(3, HIGH);
digitalWrite(0, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
}

else if (remainder == 5) {
digitalWrite(2, HIGH);
digitalWrite(1, HIGH);
digitalWrite(0, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
}

else if (remainder == 6) {
digitalWrite(2, HIGH);
digitalWrite(1, HIGH);
digitalWrite(0, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
}
else if (remainder == 7) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(6, HIGH);
}

else if (remainder == 8) {
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}

else if (remainder == 9) {
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(6, HIGH);
}
else if (remainder == 0) {
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}

else {
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}

}

Go Up