I've been thinking about a project to control the flash light on the Christmas tree since the Xmas is coming.
Therefore, I wrote a program on Arduino that provide 2 way to control the light on the tree.
First, use keyboard or Bluetooth of your smartphone to control.
Second, use buttons to control.
Check out the rough code below:
void setup()
{
pinMode(2,INPUT);
Serial.begin(9600);
}
void loop()
{
SericalControl();
}
int relayswitch(boolean status)
{
if(status == 1)
{
digitalWrite(7,HIGH);
Serial.print("relaystatus = ");
Serial.print("HIGH");
}
else
{
digitalWrite(7,LOW);
Serial.print("relaystatus = ");
Serial.print("LOW");
}
return 0;
}
void SericalControl()
{
if (Serial.available())
{
char cmd = Serial.read();
switch(cmd)
{
case '1' :
relayswitch(1);
break;
case '2':
relayswitch(0);
break;
}
}
}
void ButtonControl()
{
int bottonCmd = digitalRead(2);
if (bottonCmd == 1)
{
relayswitch(1);
}
else
{
relayswitch(0);
}
}
No comments :
Post a Comment