Ciao a tutti.. Sto cercando di portare avanti il mio progetto (realizzare un telecomando ir universale) .. prima di scrivere il codice finale, sto provando le diverse parti.. questa volta tocca alla memoria..
Sto cercando di far richiamare da Arduino Uno un codice RAW ir da un file test.txt su di una memory card.
Questo è il codice :
#include <IRremote.h>
#include <SPI.h>
#include <SD.h>
String inString = "";
File myFile;
unsigned int myArray[57];
IRsend irsend;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
//Serial.write(myFile.read());
int inChar = myFile.read();
if (isDigit(inChar)) {
inString += (char)inChar; //converte i byte in arrivo in char e li aggiunge alla stringa "inString"
}
int a = 0;
int b = 4;
for (int i = 0; i < 57; i++){
String sezione = inString.substring(a,b);
myArray[i]= sezione.toInt();
a=a+4;
b=b+4;
}
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
for (int t = 0; t < 57; t++){
Serial.println(myArray[t]);
}
int khz = 38; // 38kHz carrier frequency for the NEC protocol
unsigned int myArray[57];
irsend.sendRaw(myArray, sizeof(myArray) / sizeof(myArray[0]), khz); //Note the approach used to automatically calculate the size of the array.
delay(5000); //In this example, the signal will be repeated every 5 seconds, approximately.
}
...ma come sempre il mio problema sta nelle sintassi delle array(credo) .. in particolare , ho modificato l'esempio IRsendRawDemo così ;
int khz = 38; // 38kHz carrier frequency for the NEC protocol
unsigned int irSignal[] = {9000, 4500, 560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 39416, 9000, 2210, 560}; //AnalysIR Batch Export (IRremote) - RAW
in:
int khz = 38; // 38kHz carrier frequency for the NEC protocol
unsigned int myArray[57];
ma non funziona perchè penso che "myArray[57]" richiami solo l'array 57..
Soluzioni? come dovrei scrivere per fargli richiamare tutte le 57arrays?