Move master branch from from mios git repo
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This sketch simply repeats data received from remote weather sensors made by Cresta.
|
||||
*
|
||||
* Setup:
|
||||
* - connect digital output of a 433MHz receiver to digital pin 2 of Arduino.
|
||||
* - connect transmitter input of a 433MHz transmitter to digital pin 11
|
||||
* - An LED on pin 13 will tell you if and when a signal has been received and transmitted.
|
||||
*/
|
||||
|
||||
#include <SensorReceiver.h>
|
||||
#include <SensorTransmitter.h>
|
||||
|
||||
#define LED_PIN 13
|
||||
#define TRANSMITTER_PIN 11
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
|
||||
// Since we're not instantiating SensorTransmitter, but only use the static methods of SensorTransmitter,
|
||||
// the pin mode must be set manually.
|
||||
pinMode(TRANSMITTER_PIN, OUTPUT);
|
||||
|
||||
// When no signal has been received, the LED is lit.
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
|
||||
// Init the receiver on interrupt pin 0 (digital pin 2).
|
||||
// Set the callback to function "retransmit", which is called
|
||||
// whenever valid sensor data has been received.
|
||||
SensorReceiver::init(0, retransmit);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
void retransmit(byte *data) {
|
||||
// Data received
|
||||
|
||||
// Wait a second after a receiving. There's little point for decoding and sending the same signal multiple times.
|
||||
SensorReceiver::disable();
|
||||
interrupts(); // delay() requires that interrupts are enabled
|
||||
delay(1000);
|
||||
|
||||
// Flash LED when transmitting.
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
|
||||
// Transmit signal. Note: this is a static method, no object required!
|
||||
SensorTransmitter::sendPackage(TRANSMITTER_PIN, data);
|
||||
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
|
||||
noInterrupts();
|
||||
SensorReceiver::enable();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This sketch receives and decodes data from a 433MHz thermo/hygro weather sensor.
|
||||
* The received data (temperature, humidity, channel) is echo
|
||||
*
|
||||
* Setup:
|
||||
* - Connect digital output of a 433MHz receiver to digital pin 2 of Arduino
|
||||
* - Enable the serial monitor at 115200 baud.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SensorReceiver.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Init the receiver on interrupt pin 0 (digital pin 2).
|
||||
// Set the callback to function "showTempHumi", which is called
|
||||
// whenever valid sensor data has been received.
|
||||
SensorReceiver::init(0, showTempHumi);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Empty! However, you can do other stuff here if you like.
|
||||
}
|
||||
|
||||
void showTempHumi(byte *data) {
|
||||
// is data a ThermoHygro-device?
|
||||
if ((data[3] & 0x1f) == 0x1e) {
|
||||
// Yes!
|
||||
|
||||
byte channel, randomId;
|
||||
int temp;
|
||||
byte humidity;
|
||||
|
||||
// Decode the data
|
||||
SensorReceiver::decodeThermoHygro(data, channel, randomId, temp, humidity);
|
||||
|
||||
// Print temperature. Note: temp is 10x the actual temperature!
|
||||
Serial.print("Temperature: ");
|
||||
Serial.print(temp / 10); // units
|
||||
Serial.print('.');
|
||||
Serial.print(temp % 10); // decimal
|
||||
|
||||
// Print humidity
|
||||
Serial.print(" deg, Humidity: ");
|
||||
Serial.print(humidity);
|
||||
Serial.print("% REL");
|
||||
|
||||
// Print channel
|
||||
Serial.print(", Channel: ");
|
||||
Serial.println(channel, DEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This sketch sends (bogus) thermo / hygro data to a remote weather sensors made by Cresta.
|
||||
*
|
||||
* Setup:
|
||||
* - connect transmitter input of a 433MHz transmitter to digital pin 11
|
||||
* - On the weather station, activate the "scan" function for channel 1.
|
||||
*/
|
||||
|
||||
#include <SensorTransmitter.h>
|
||||
|
||||
// Initializes a ThermoHygroTransmitter on pin 11, with "random" ID 0, on channel 1.
|
||||
ThermoHygroTransmitter transmitter(11, 0, 1);
|
||||
|
||||
void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Displays temperatures from -10 degrees Celsius to +20,
|
||||
// and humidity from 10% REL to 40% REL, with increments of 2
|
||||
for (int i = -10; i<=20; i+=2) {
|
||||
// Temperatures are passed at 10 times the real value,
|
||||
// to avoid using floating point math.
|
||||
transmitter.sendTempHumi(i * 10, i + 20);
|
||||
|
||||
// Wait two seconds before sending next.
|
||||
delay(2000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user