mirror of
https://github.com/KevinMidboe/Arduino.git
synced 2025-10-29 17:40:11 +00:00
Init commit with many years of arduino sketches and projects. I dont know if the esp8266 includes much, but there are also libraries. I hope they dont have crazy automatic versioning through the Arduino IDE.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#include <Servo.h>
|
||||
|
||||
int relayPins[] = {4, 7, 6, 5};
|
||||
int buttonPins[] = {8, 9, 10, 11, 12, 13};
|
||||
int relayState[] = {0, 0, 0, 0};
|
||||
int buttonState = 0;
|
||||
|
||||
Servo myservo;
|
||||
|
||||
void setup() {
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (i < 4)
|
||||
{
|
||||
pinMode(relayPins[i], OUTPUT);
|
||||
}
|
||||
pinMode(buttonPins[i], INPUT_PULLUP);
|
||||
}
|
||||
|
||||
myservo.attach(3);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
buttonState = digitalRead(buttonPins[i]);
|
||||
if (buttonState == LOW)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 4:
|
||||
//
|
||||
break;
|
||||
case 3:
|
||||
// Turn on the servo for speaker
|
||||
myservo.write(150);
|
||||
delay(1000);
|
||||
myservo.write(140);
|
||||
break;
|
||||
default:
|
||||
relayChange(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (buttonState == LOW)
|
||||
{
|
||||
delay(50);
|
||||
buttonState = digitalRead(buttonPins[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void relayChange(int i)
|
||||
{
|
||||
if (relayState[i] == 0)
|
||||
{
|
||||
digitalWrite(relayPins[i], HIGH);
|
||||
relayState[i] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(relayPins[i], LOW);
|
||||
relayState[i] = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user