i am trying to make a arduino send a infrared signal when it receives a specific word from the terminal. It is working now but it disconnects after the word has been send once. I can’t figure out how to avoid this. The code reads the infrared codes from sd card files.
A file looks like this:
1234/
123/
45568/
546/
etc.
#include <SD.h>
int ircoderry[77];
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
WidgetTerminal terminal(V1);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
pinMode(9, OUTPUT);
pinMode(4, OUTPUT);
SD.begin(4); //sdkaart activeren
Blynk.begin("d1180c442b4f470fa8c5874aaeb35344");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BLYNK_WRITE(V1)
{
String terminalout = param.asStr();
if (String(F("au")) == terminalout) {
terminal.println(F("k"));
arrayer(F("aanuitt.txt"));
}
terminal.flush();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void arrayer(String filee) {
File dataFile = SD.open(filee);
char numcom[6];
if (dataFile) {
for (byte indexx = 0; indexx <= 77; indexx++) {
for (byte index = 0; index <= 6; index++) {
delayMicroseconds(1000);
char fille = dataFile.read();
if (fille != '/') {
numcom[index] = fille;
}
else {
ircoderry[indexx] = atoi(numcom);
index = 7;
}
}
}
dataFile.close();
irsend();
}
else {
dataFile.close();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
Blynk.run();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void pulseIR(long microsecs) {
cli();
while (microsecs > 0) {
// 38 kHz is about 13 microseconds high and 13 microseconds low
digitalWrite(9, HIGH);
delayMicroseconds(10);
digitalWrite(9, LOW);
delayMicroseconds(10);
// so 26 microseconds altogether
microsecs -= 26;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void irsend() {
for (byte indexxx = 0; indexxx <= 77; indexxx++) {
delayMicroseconds(ircoderry[indexxx]);
indexxx++;
pulseIR(ircoderry[indexxx]);
}
}