I feel that we have gotten a bit off topic... i am sorry. i attached a pdf of my current schematic sorry it is kind hard to read slapped it together really quick. so you can see what i am working with.
const int fwButton = A2;
const int ntButton = A3;
const int rvButton = A4;
const int fwLed = 2;
const int ntLed = 3;
const int rvLed = 4;
const int bz = 8;
int brightness = 0;
int fadeAmt = 20;
const long fadeInt = 100;
int fwState = 0;
int ntState = 0;
int rvState = 0;
int shiftState = 0;
//THROTTLE CALL OUTS
const int numReadings = 20;
int readThrottle1[numReadings];
//int readThrottle2[numReadings;
int throttle1Index = 0;
//int throttle2Index = 0;
int throttle1Total = 0;
//int throttle2Total = 0;
int throttle1Average = 0;
//int throttle2Average = 0;
const int throttle1Source = A0;
//const int throttle2Source = A1;
int throttle1 = 0;
//int throttle2 = 0;
int Oldthrottle1 = 0;
//int Oldthrottle2 = 0;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
void setup() {
Serial.begin(9600);
pinMode(bz, OUTPUT);
pinMode(fwButton, INPUT);
//pinMode(ntButton, INPUT);
pinMode(rvButton, INPUT);
pinMode(fwLed, OUTPUT);
//pinMode(ntLed, OUTPUT);
pinMode(rvLed, OUTPUT);
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readThrottle1[thisReading] = 0;
}
beep(50);
beep(50);
beep(50);
}
void loop() {
fwState = digitalRead(fwButton);
ntState = digitalRead(ntButton);
rvState = digitalRead(rvButton);
// throttle1 = analogRead(throttle1Source);
// throttle2 = analogRead(throttle2Source);
if (fwState == 1 && rvState == 0 && ntState == 0) {
shiftState = 1;
analogWrite(bz, 100);
}
if (fwState == 0 && rvState == 0 && ntState == 1) {
shiftState = 2;
analogWrite(bz, 100);
}
if (fwState == 0 && rvState == 1 && ntState == 0) {
shiftState = 3;
analogWrite(bz, 100);
}
if (fwState == 0 && rvState == 0 && ntState == 0) {
analogWrite(bz, 0);
}
// subtract the last reading:
throttle1Total = throttle1Total - readThrottle1[throttle1Index];
// read from the sensor:
readThrottle1[throttle1Index] = analogRead(throttle1Source);
// add the reading to the total:
throttle1Total = throttle1Total + readThrottle1[throttle1Index];
// advance to the next position in the array:
throttle1Index = throttle1Index + 1;
// if we're at the end of the array...
if (throttle1Index >= numReadings) {
// ...wrap around to the beginning:
throttle1Index = 0;
}
// calculate the average:
throttle1Average = throttle1Total / numReadings;
// send it to the computer as ASCII digits
//Serial.println(throttle1Average);
if (throttle1Average > Oldthrottle1 + 4 || throttle1Average < Oldthrottle1 - 4 ) {
Serial.println(throttle1Average);
Oldthrottle1 = throttle1Average;
}
fade();
}
void beep(unsigned char delayms) {
analogWrite(bz, 100); // Almost any value can be used except 0 and 255
delay(delayms); // wait for a delayms ms
analogWrite(bz, 0); // 0 turns it off
delay(delayms); // wait for a delayms ms
}
void fade() {
currentMillis = millis();
if (currentMillis - previousMillis >= fadeInt) {
previousMillis = currentMillis;
brightness = brightness + fadeAmt;
if (brightness <= 0 || brightness >= 255) {
fadeAmt = -fadeAmt;
}
if (shiftState == 0) {
analogWrite(fwLed, brightness);
analogWrite(ntLed, brightness);
analogWrite(rvLed, brightness);
}
if (shiftState == 1) {
analogWrite(fwLed, brightness);
analogWrite(ntLed, 25);
analogWrite(rvLed, 25);
}
if (shiftState == 2) {
analogWrite(ntLed, brightness);
analogWrite(fwLed, 25);
analogWrite(rvLed, 25);
}
if (shiftState == 3) {
analogWrite(rvLed, brightness);
analogWrite(ntLed, 25);
analogWrite(fwLed, 25);
}
}
}
throttle.ino (3.82 KB)
throttle board.PDF (216 KB)