Arduino-IDE öffnen -> Datei -> Beispiele -> 01.Basic -> Blink
Hast du irgendeinen Sketch der permanent einfach etwas sendet, zum Beispiel alle 5 Sekunden um die Sender mal zu testen?
Auch das kann man einfach gestalten:
Spoiler anzeigen
C
#include <RFM12B.h>
#include <avr/sleep.h>
//--------------------------------------------------------------------------------------------------
#define FREQ RF12_433MHZ
#define NODEID 19 // network ID used for this unit
#define NETWORKID 210 // the network ID we are on
#define GATEWAYID 0 // the node ID we're sending to (22). Set to 0 for broadcast to all
#define ACK_TIME 2000 // # of ms to wait for an ack
#define requestACK false // request ACK? (true/false)
#define SENDDELAY 30000 // wait this many ms between sending packets. 30000ms = 30sec
// LED pin
#define LEDpin 0 // D8, PA2 (ATtiny pin 11) - set to 0 to disable LED
//--------------------------------------------------------------------------------------------------
// Need an instance of the Radio Module
RFM12B radio;
// Variablen für Temperatur/Luftfeuchtigkeit
long temp; long humi;
// Temperatur-String zum Versand per 433 Mhz
char msg[26];
//--------------------------------------------------------------------------------------------------
static void activityLed (byte state, byte time = 0) {
if (LEDpin) {
pinMode(LEDpin, OUTPUT);
if (time == 0) {
digitalWrite(LEDpin, state);
} else {
digitalWrite(LEDpin, state);
delay(time);
digitalWrite(LEDpin, !state);
}
}
}
// blink led
static void blink (byte pin, byte n = 3) {
if (LEDpin) {
pinMode(pin, OUTPUT);
for (byte i = 0; i < 2 * n; ++i) {
delay(100);
digitalWrite(pin, !digitalRead(pin));
}
}
}
long readVcc() {
bitClear(PRR, PRADC);
ADCSRA |= bit(ADEN); // Enable the ADC
long result;
// Read 1.1V reference against Vcc
#if defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0); // For ATtiny84
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); // For ATmega328
#endif
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate Vcc in mV
ADCSRA &= ~ bit(ADEN);
bitSet(PRR, PRADC); // Disable the ADC to save power
return result;
}
// init Setup
void setup() {
radio.Initialize(NODEID, FREQ, NETWORKID);
// configure RFM12B
radio.Control(0xC040); // Adjust low battery voltage to 2.2V
radio.Sleep(0); //sleep right away to save power
ADCSRA &= ~(1<<ADEN); //Disable ADC, saves ~230uA
//ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
PRR = bit(PRTIM1); // only keep timer 0 going
analogReference(INTERNAL); // Set the aref to the internal 1.1V reference
if (LEDpin) {
activityLed(1,1000); // LED on
}
}
// Loop
void loop() {
//activityLed(1); // LED on
int temp = 9900;
int humi = 6600;
int vcc = readVcc(); // Get supply voltage
// msg-Variable mit Daten zum Versand fuellen, die spaeter an das WebScript uebergeben werden
//snprintf(msg, 26, "v=%d&t=%d&h=%d", vcc,temp,humi);
strcpy(msg,"v=");
itoa(vcc,&msg[strlen(msg)],10);
strcat(msg,"&t=");
itoa(temp,&msg[strlen(msg)],10);
strcat(msg,"&h=");
itoa(humi,&msg[strlen(msg)],10);
radio.Wakeup();
radio.Send(GATEWAYID, (uint8_t *)msg, strlen(msg), requestACK);
radio.SendWait(2); //wait for RF to finish sending (2=standby mode, 3=power down)
radio.Sleep(0);
if (LEDpin) {
blink(LEDpin, 2); // blink LED
}
ADCSRA &= ~ bit(ADEN); // disable the ADC
bitSet(PRR, PRADC); // power down the ADC
delay(SENDDELAY);
}
Alles anzeigen