This is an intro to computer science problem. I keep running my current code through Arduino, but I get a ton of errors. Can someone write one that has no errors?
How do you write the code with "Arduino" that does the following?
1a. The voltage produced by the motor/generator will be read from the Arduino and displayed on the screen every 0.5 seconds.
1b. If the voltage produced is 0, both LEDs are off.
1c. If the voltage produced is between 0 and 0.5V, only the Green LED turns on for 5 seconds.
1d. If the voltage produced is more than 0.5V, only the Red LED turns on for 5 seconds.
int motorPin = A0; //connect motor to A6
int redLed=6; //connect anode of red led to pin 6
int greenLed=7; //connect anode of green led to pin 7
float voltage = 0;
void setup() {
Serial.begin(9600); // setup serial
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}
void loop() {
voltage = analogRead(motorPin)*(5.0/1024); // read the input
pin
Serial.println(voltage); // debug value
delay(500);
if(voltage<0.5) //if input voltage is less than 0.5V
{
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
delay(5000);
}
else //if input voltage is greater than 0.5V
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
delay(5000);
}
}
Get Answers For Free
Most questions answered within 1 hours.