Para dar os primeiros passos no arduino, comprei um kit de iniciação e já fiz algumas pequenas coisas.
Brico com leds, ja controlo bem motores, sensores de luz e temperatura, sensores de proximidade e outras coisas afins.
No entanto, não consigo trabalhar com o transmissor e receptor que vinha no KIT.
Ele tem a referencia FS1000A
Ja procurei imenso codigo, e nao consigo de forma nenhuma.
Um dos que testei foi este, que tentei alterar a gosto:
#define NETWORK_SIG_SIZE 3
#define VAL_SIZE 2
#define CHECKSUM_SIZE 1
#define PACKET_SIZE (NETWORK_SIG_SIZE + VAL_SIZE + CHECKSUM_SIZE)
#define NET_ADDR 5
const byte g_network_sig[NETWORK_SIG_SIZE] = {0x8F, 0xAA, NET_ADDR}; // Few bytes used to initiate a transfer
#define LED_PIN 8
void setup()
{
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.begin(1200);
}
void loop()
{
digitalWrite(LED_PIN, HIGH);
writeUInt(271); // Put any number you want to send here (71 is just a test)
delay(1000);
digitalWrite(LED_PIN, LOW);
delay(5000); // Debounce button
}
//#ifdef RECEIVER
//void loop()
//{
// boolean light_led = false;
// if (readUInt(true) == 271) // Check to see if we got the 71 test number
//{
// light_led = true;
// }
//if (light_led)
// {
// digitalWrite(LED_PIN, HIGH);
// delay(1000);
// digitalWrite(LED_PIN, LOW);
// }
//}
// Sends an unsigned int over the RF network
void writeUInt(unsigned int val)
{
byte checksum = (val/256) ^ (val&0xFF);
Serial.write(0xF0); // This gets reciever in sync with transmitter
Serial.write(g_network_sig, NETWORK_SIG_SIZE);
Serial.write((byte*)&val, VAL_SIZE);
Serial.write(checksum); //CHECKSUM_SIZE
}
// Receives an unsigned int over the RF network
unsigned int readUInt(bool wait)
{
int pos = 0; // Position in the network signature
unsigned int val; // Value of the unsigned int
byte c = 0; // Current byte
if((Serial.available() < PACKET_SIZE) && (wait == false))
{
return 0xFFFF;
}
while(pos < NETWORK_SIG_SIZE)
{
while(Serial.available() == 0); // Wait until something is avalible
c = Serial.read();
if (c == g_network_sig[pos])
{
if (pos == NETWORK_SIG_SIZE-1)
{
byte checksum;
while(Serial.available() < VAL_SIZE + CHECKSUM_SIZE); // Wait until something is avalible
val = Serial.read();
val += ((unsigned int)Serial.read())*256;
checksum = Serial.read();
if (checksum != ((val/256) ^ (val&0xFF)))
{
// Checksum failed
pos = -1;
}
}
++pos;
}
else if (c == g_network_sig[0])
{
pos = 1;
}
else
{
pos = 0;
if (!wait)
{
return 0xFFFF;
}
}
}
return val;
}
Alguem me pode ajudar?