Created
January 6, 2023 02:09
-
-
Save Rushilwiz/134476df1e1760a642a0e7b1072a75db to your computer and use it in GitHub Desktop.
arduino code for the time scheduled desk lamp I have
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// include the Time library | |
#include <Time.h> | |
// define the pin that the light is connected to | |
const int LIGHT_PIN = 9; | |
// set the time that the light should be turned off | |
const int TURN_OFF_HOUR = 22; // 22:00 (10:00 PM) | |
const int TURN_OFF_MINUTE = 0; | |
void setup() { | |
// set the light pin to be an output | |
pinMode(LIGHT_PIN, OUTPUT); | |
} | |
void loop() { | |
// get the current time | |
time_t currentTime; | |
getLocalTime(¤tTime); | |
// if it is time to turn off the light, do so | |
if (hour(currentTime) == TURN_OFF_HOUR && minute(currentTime) == TURN_OFF_MINUTE) { | |
digitalWrite(LIGHT_PIN, LOW); | |
} | |
// otherwise, turn the light on | |
else { | |
digitalWrite(LIGHT_PIN, HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment