Hi,
Dumb question; I am trying to have these motors for 2 seconds run when the button is not pressed. I think I have everything wired up right and that my code is working.
//DataSlate
int buttonState = 0;
int speaker = 9;
//digitalWrite(LED_BUILTIN, HIGH);
//L293D Motor A
int motorPin1 = 5;
int motorPin2 = 6;
//L293D Motor B
int motorPin3 = 11;
int motorPin4 = 10;
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(LED_BUILTIN, OUTPUT); //used to test functionality of code
//Motors
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}
void loop()
{
buttonState = digitalRead(2);
if (Serial.available () > 0) {
String command = Serial.readStringUntil('\n');
//Signal is standing in for a command signal from an external device
if (command == "signal"){//A3
for (long i = 0; i < 2048 * 3; i++ )
{
//ouchy ear noise
digitalWrite(speaker, HIGH);
delayMicroseconds(500);
digitalWrite(speaker, LOW);
delayMicroseconds(500);
}
}
}
//main process
if (buttonState == HIGH){
//nothing happens as user stopped action
delay(10);
} else if (buttonState == LOW){
//User did not cancel action window will now open.
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, HIGH);
delay(2000);
}
}//1
The speaker portion of this is working, but I think I am missing something with the controller.
Thanks in advance for the help.