This was just a proof of concept for the VW Bug project.. Now that I have gotten this to work, I can slowly add more elements into the mix..
Code:
(This is just proof of concept code)(The serial outputs are solely for debugging purposes)
int ledPB = 13;
int ledLION = 12;
int ignON;//5
int pbBatt;//A0
int lionBatt;//A1
int dcMotor; //7
void setup() {
// put your setup code here, to run once:
pinMode (A0, INPUT);
pinMode (A1, INPUT);
pinMode (ledPB, OUTPUT);
pinMode (ledLION, OUTPUT);
pinMode (5, INPUT);
pinMode (7, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int ignVal = digitalRead(4);
if (int ignVal = digitalRead(4) == HIGH){
startup();
Serial.println (ignVal);
}
else{
dcMtrCrl(0);
}
}
void dcMtrCrl (int x) {
digitalWrite(7, x);
}
void startup(){
int pbVal = analogRead(A0);
int lionVal = analogRead(A1);
int pbCharged = 0;
int pbtotal = pbVal / 204;
int lionCharged = 0;
int liontotal = lionVal / 204;
if (liontotal >= 4){
lionCharged = 1;
Serial.println("lion");
Serial.print(liontotal);
}
else {
lionCharged = 0;
dcMtrCrl(0);
}
if (pbtotal >= 4){
pbCharged = 1;
Serial.println("pb");
Serial.print(pbtotal);
}
else {
pbCharged = 0;
dcMtrCrl(0);
}
if (pbCharged == 1 || lionCharged == 1){
dcMtrCrl(HIGH);
}
else {
dcMtrCrl(0);
}
}
No comments:
Post a Comment