with leanings from - http://www.stanford.edu/~sanjayd/gear_indicator.pdf
once I know it works might paste it on gstwin.com
here is the code - let me know if I need to pastebin
// assume 7segment anode common
// might need pulldown resistors on the gear inputs 8-13
// might need a filter,etc for the inputs
// would really like to use a 4 bit to 7 segment toget away from using 1,2,13 inputs
int Gear1 = 8;
int Gear2 = 9;
int Gear3 = 10;
int Gear4 = 11;
int Gear5 = 12;
int Gear6 = 13;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
void setup()
{
pinMode(0,HIGH);
pinMode(1,HIGH);
pinMode(2,HIGH);
pinMode(3,HIGH);
pinMode(4,HIGH);
pinMode(5,HIGH);
pinMode(6,HIGH);
pinMode(Gear1,INPUT);
pinMode(Gear2,INPUT);
pinMode(Gear3,INPUT);
pinMode(Gear4,INPUT);
pinMode(Gear5,INPUT);
pinMode(Gear6,INPUT);
}
void loop()
{
PORTD=B0111111; // clear for no data aka netural
buttonState1 = digitalRead(Gear1);
buttonState2 = digitalRead(Gear2);
buttonState3 = digitalRead(Gear3);
buttonState4 = digitalRead(Gear4);
buttonState5 = digitalRead(Gear5);
buttonState6 = digitalRead(Gear6);
if (buttonState1>0){PORTD=B1111001;} // 1
if (buttonState2>0){PORTD=B0100100;} // 2
if (buttonState3>0){PORTD=B0110000;} // 3
if (buttonState4>0){PORTD=B0011001;} // 4
if (buttonState5>0){PORTD=B0010010;} // 5
if (buttonState6>0){PORTD=B0000010;} // 6
delay(500); // delay in between reads for stability
}
No comments:
Post a Comment