So I’m new to Arduino and have very limited programming experience. I have a sketch setup that is basically a timer to control functions on a light for a fish tank via an IR emitter. I have it working right now for the basic functions, but I also want it to randomly send the IR command for the light to go into thunderstorm mode. I haven’t decoded all of the function for the IR remote yet, so this sketch only has the PowerButton in it. I have the Hex codes for the functions as well, so I’m hoping to changed from the delay format here to hex on the PWM channel in the future to save code space.
I have no idea how to proceed to randomly cause the t-storm function to occur.
Here’s what I have right now (be gentle, it’s my first time haha). It’s basically just an alarm that fires the emitter at certain times.
////////////SETUP//////////////////////////////////////////////////
#include <Time.h>
#include <TimeAlarms.h>
#include <DateTime.h>
#include <DateTimeStrings.h>
int IRledPin = 13; // Pin location for IR output
void setup()
{ pinMode(IRledPin, OUTPUT); // Designate IRledPin as Output
Serial.begin(9600); // Connect @ (Baud)
setTime(8,29,0,1,1,11); // set time (HR,MIN,SEC,MO,DAY,YR)
////////////ALARM FUNCTIONS/////////////////////////////////////////
Alarm.alarmRepeat(8,30,0, PowerButton); // (HR,MIN,SEC,FUNCTION)
////////////CLOCK///////////////////////////////////////////////////
void loop(){
digitalClockDisplay();
Alarm.delay(1000); } // Clock display update frequency (msec)
void digitalClockDisplay() // Digital clock
{ Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println(); }
void printDigits(int digits) // Add :
{Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);}
////////////SIGNAL///////////////////////////////////////////////////
// Create Frequency (38khz/26msec)
void pulseIR(long microsecs)
{ cli(); // kill interupts
while (microsecs > 0)
{ digitalWrite(IRledPin, HIGH); // ~3 msec
delayMicroseconds(7); // ~delay
digitalWrite(IRledPin, LOW); // ~3 msec
delayMicroseconds(7); // ~delay
microsecs -= 26; }
sei(); } // zombie interupts
////////////FIXTURE FUNCTIONS////////////////////////////////////////
void PowerButton() //Fixture power on/off toggle
{ pulseIR(8840);
delayMicroseconds(4320);
pulseIR(620);
delayMicroseconds(480);
pulseIR(600);
delayMicroseconds(500);
pulseIR(540);
delayMicroseconds(1660);
pulseIR(580);
delayMicroseconds(520);
pulseIR(520);
delayMicroseconds(560);
pulseIR(600);
delayMicroseconds(480);
pulseIR(620);
delayMicroseconds(480);
pulseIR(540);
delayMicroseconds(540);
pulseIR(620);
delayMicroseconds(1600);
pulseIR(520);
delayMicroseconds(1660);
pulseIR(580);
delayMicroseconds(520);
pulseIR(520);
delayMicroseconds(1660);
pulseIR(600);
delayMicroseconds(1580);
pulseIR(620);
delayMicroseconds(1580);
pulseIR(540);
delayMicroseconds(1660);
pulseIR(600);
delayMicroseconds(1580);
pulseIR(600);
delayMicroseconds(500);
pulseIR(600);
delayMicroseconds(500);
pulseIR(520);
delayMicroseconds(560);
pulseIR(600);
delayMicroseconds(500);
pulseIR(600);
delayMicroseconds(500);
pulseIR(520);
delayMicroseconds(560);
pulseIR(580);
delayMicroseconds(1620);
pulseIR(540);
delayMicroseconds(540);
pulseIR(600);
delayMicroseconds(1600);
pulseIR(520);
delayMicroseconds(1660);
pulseIR(580);
delayMicroseconds(1620);
pulseIR(580);
delayMicroseconds(1620);
pulseIR(520);
delayMicroseconds(1660);
pulseIR(580);
delayMicroseconds(1600);
pulseIR(580);
delayMicroseconds(520);
pulseIR(580);
delayMicroseconds(1620);
pulseIR(540);
delayMicroseconds(38980);
pulseIR(8860);
delayMicroseconds(2120);
pulseIR(620); }