eil
Forum Sage
When programming microcontrollers, the golden rule usually is: if it works, it works! But of course, there's always room for improvement, right? (The forum software seems to have destroyed my indentation, so just imagine proper indentation below. Good indentation is very important!)
Gear selector pins could be an array, e.g.:
// Gear indicator pins, gear[0] is Neutral, gear[1] is first, etc
// Or you could make the order match the shift pattern (1N23456), but there's probably no real reason to
int gear[] = {40, 52, 50, 48, 46, 44, 42};
Be sure to make variable names descriptive, so instead of just "Delay":
int animationDelay = 200;
For loops are your friend:
int i; // declare this somewhere near the top of setup()
// Set LED segment pins mode
for (i = 2; i <= 0; i++) {
pinMode(i, OUTPUT);
}
// Set gear selector pins mode and pull HIGH
// (Building on the gear indicator pin array above)
for (i = 0; i < 7; i++) {
pinMode(gear, INPUT);
digitalWrite(gear, HIGH);
}
I'd stick all of the gear display stuff into a function. You just call the function with the gear to display as a parameter. That way, you don't have to write it twice and makes the main body of code much easier to read. This would be an excellent use of the "switch" statement.
Gear selector pins could be an array, e.g.:
// Gear indicator pins, gear[0] is Neutral, gear[1] is first, etc
// Or you could make the order match the shift pattern (1N23456), but there's probably no real reason to
int gear[] = {40, 52, 50, 48, 46, 44, 42};
Be sure to make variable names descriptive, so instead of just "Delay":
int animationDelay = 200;
For loops are your friend:
int i; // declare this somewhere near the top of setup()
// Set LED segment pins mode
for (i = 2; i <= 0; i++) {
pinMode(i, OUTPUT);
}
// Set gear selector pins mode and pull HIGH
// (Building on the gear indicator pin array above)
for (i = 0; i < 7; i++) {
pinMode(gear, INPUT);
digitalWrite(gear, HIGH);
}
I'd stick all of the gear display stuff into a function. You just call the function with the gear to display as a parameter. That way, you don't have to write it twice and makes the main body of code much easier to read. This would be an excellent use of the "switch" statement.
Last edited: