So hopefully this schematic will explain what i'm doing well enough.
The problem i am having is that my A0 (and all other input pins) are somehow breaking my reading- w/o the arduino hooked up I read specific ranges for each gear (check the schematic) - but as soon as I connect the A0 pin to the wire it should read voltage from- it locks up on 3.98 volts- and doesn't budge.
Why would this happen?
Schematic:
All of my so-so code:
const int bottomLeft = 3;
const int bottom = 6;
const int bottomRight = 2;
const int topRight = 7;
const int top = 1;
const int topLeft = 4;
const int middle = 5;
void setup() {
pinMode(bottomLeft, OUTPUT);
pinMode(bottom, OUTPUT);
pinMode(bottomRight, OUTPUT);
pinMode(topRight, OUTPUT);
pinMode(top, OUTPUT);
pinMode(topLeft, OUTPUT);
pinMode(middle, OUTPUT);
pinMode(A0, INPUT);
//debug
//Serial.begin(9600);
}
int incomingByte = 0;
int prevByte = 2;
int currentByte = 0;
int testing = 0;
void loop() {
if (testing == 1){
test();
//digitalWrite(6,HIGH); // test individual segments
}else{
int raw = 0;
float val = 0;
float avgVal = 0;
for (int i=0; i <= 99; i++){
raw = analogRead(A0); // read 0-5 volts from the GPS
val = fmap(raw, 0, 1023, 0.0, 5.0); // volts are 10 bit (0-1023) so map it back to a proper volt number
avgVal = avgVal+val;
}
//Serial.println(avgVal/100); //voltage
//1st: 1.36V
//2nd: 1.77V
//3rd: 2.49V
//4th: 3.23V
//5th: 4.1V
//6th: 4.55V
//N: 5V
if (avgVal <= 4.24){
reset();
first();
}
if (avgVal >= 4.25 && avgVal <= 4.31){
second();
}
if (avgVal >= 4.32 && avgVal <= 4.40){
third();
}
if (avgVal >= 4.41 && avgVal <= 4.56){
fourth();
}
if (avgVal >= 4.57 && avgVal <= 4.72){
fifth();
}
if (avgVal >= 4.73 && avgVal <= 4.89){
sixth();
}
if (avgVal >= 4.90){
neutral();
}
delay(1);
}
}
void reset(){
digitalWrite(bottomRight,HIGH);
digitalWrite(bottom,HIGH);
digitalWrite(bottomLeft,HIGH);
digitalWrite(topRight,HIGH);
digitalWrite(top,HIGH);
digitalWrite(topLeft,HIGH);
digitalWrite(middle,HIGH);
}
void first(){
reset();
digitalWrite(topRight,LOW);
digitalWrite(bottomRight,LOW);
}
void second(){
reset();
digitalWrite(top,LOW);
digitalWrite(topRight,LOW);
digitalWrite(middle,LOW);
digitalWrite(bottomLeft,LOW);
digitalWrite(bottom,LOW);
}
void third(){
reset();
digitalWrite(top,LOW);
digitalWrite(topRight,LOW);
digitalWrite(middle,LOW);
digitalWrite(bottomRight,LOW);
digitalWrite(bottom,LOW);
}
void fourth(){
reset();
digitalWrite(topLeft,LOW);
digitalWrite(middle,LOW);
digitalWrite(topRight ,LOW);
digitalWrite(bottomRight,LOW);
}
void fifth(){
reset();
digitalWrite(top,LOW);
digitalWrite(topLeft,LOW);
digitalWrite(middle,LOW);
digitalWrite(bottomRight,LOW);
digitalWrite(bottom,LOW);
}
void sixth(){
reset();
digitalWrite(top,LOW);
digitalWrite(topLeft,LOW);
digitalWrite(bottomLeft,LOW);
digitalWrite(bottom,LOW);
digitalWrite(bottomRight,LOW);
digitalWrite(middle,LOW);
}
//animated neutral "spins"
void neutral(){
digitalWrite(bottomLeft,LOW);
delay(100);
reset();
digitalWrite(bottom,LOW);
delay(100);
reset();
digitalWrite(bottomRight,LOW);
delay(100);
reset();
digitalWrite(topRight,LOW);
delay(100);
reset();
digitalWrite(top,LOW);
delay(100);
reset();
digitalWrite(topLeft,LOW);
delay(100);
reset();
}
void test(){
first();
delay(1000);
second();
delay(1000);
third();
delay(1000);
fourth();
delay(1000);
fifth();
delay(1000);
sixth();
delay(1000);
}
//Mapping function, used to convert 0-1023 to 0-5 volts
float fmap(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}