I wanted to make a code that turns a moter 0.5 seconds every day. It is a motor on pin D5 and D16 it works on 3 AA batteries. I don't know much about coding but i used mBlock and it didn't work. Here is the code i had.
// generated by mBlock5 for <your product>
// codes make you happy
// generated by mBlock5 for <your product>
// codes make you happy
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
void _delay(float seconds) {
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}
void setup() {
pinMode(5,OUTPUT);
pinMode(16,OUTPUT);
while(1) {
digitalWrite(5,1);
_delay(0.5);
digitalWrite(16,0);
_delay(86400);
_loop();
}
}
void _loop() {
}
void loop() {
_loop();
}
Here is an Arduino sketch that will do basically what your code is doing:
const unsigned long SECONDS = 1000ul;
const unsigned long MINUTES = SECONDS * 60;
const unsigned long HOURS = MINUTES * 60;
const unsigned long DAYS = HOURS * 24;
void setup()
{
pinMode(5, OUTPUT);
pinMode(16, OUTPUT);
}
void loop()
{
static unsigned long startTime = 0;
if (millis() - startTime >= (DAYS * 1))
{
startTime += (DAYS * 1);
digitalWrite(5, HIGH);
delay(500);
digitalWrite(16, LOW);
}
}
I don't know how setting Pin 5 HIGH and Pin 16 LOW once each day will turn a motor on and off. After the first day, 5 will be HIGH and 16 will be LOW forever.
So, what you want is the Blink Example except with an on-time of 500ms and an off-time of 86,399,500ms.
Note that the Arduino's oscillator isn't as good as a digital wristwatch and there will be some drift. Probably several seconds or more everyday. The error will be fairly constant so if you can figure-out how much error there is, you can tweak the off-time (if it's that important).
<Error>
<Code>AccessDenied</Code>
<Message>Access denied.</Message>
<Details>Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.</Details>
</Error>