Arduino Code

Arduino Code

int m0Clockwise = 1;
int m1Clockwise = 1;
int m2Clockwise = 1;
int m3Clockwise = 1;
int m0Delay = 3000;
int m1Delay = 3000;
int m2Delay = 3000;
int m3Delay = 3000;

void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
Serial.begin(9600);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(12, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(12, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);

}

void loop() {
int a0SensorValue = analogRead(A0);
int a1SensorValue = analogRead(A1);
int a2SensorValue = analogRead(A2);
int a3SensorValue = analogRead(A3);
Serial.print(a0SensorValue);
Serial.print(“, “);
Serial.print(a1SensorValue);
Serial.print(“, “);
Serial.print(a2SensorValue);
Serial.print(“, “);
Serial.println(a3SensorValue);
delay(100);
if(a0SensorValue > 200) {
if(m0Clockwise) {
digitalWrite(5, HIGH);
delay(3000);
digitalWrite(5, LOW);
m0Clockwise = 0;
}
else {
digitalWrite(6, HIGH);
delay(3000);
digitalWrite(6, LOW);
m0Clockwise = 1;
}
}
if(a1SensorValue > 200) {
if(m1Clockwise) {
digitalWrite(3, HIGH);
delay(3000);
digitalWrite(3, LOW);
m1Clockwise = 0;
}
else {
digitalWrite(4, HIGH);
delay(3000);
digitalWrite(4, LOW);
m1Clockwise = 1;
}
}
if(a2SensorValue > 200) {
if(m2Clockwise) {
digitalWrite(9, HIGH);
delay(3000);
digitalWrite(9, LOW);
m2Clockwise = 0;
}
else {
digitalWrite(10, HIGH);
delay(3000);
digitalWrite(10, LOW);
m2Clockwise = 1;
}
}
if(a3SensorValue > 200) {
if(m3Clockwise) {
digitalWrite(12, HIGH);
delay(3000);
digitalWrite(12, LOW);
m3Clockwise = 0;
}
else {
digitalWrite(11, HIGH);
delay(3000);
digitalWrite(11, LOW);
m3Clockwise = 1;
}
}

}

Post a Comment