added Documentation
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
39
examples/SendOnButton/SendOnButton.ino
Normal file
39
examples/SendOnButton/SendOnButton.ino
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
This sketch demonstrates, how to use the SoftRS485 library.
|
||||
It listens on the RS485 network bus.
|
||||
When the button is pressed, it sends some messages on the bus.
|
||||
*/
|
||||
|
||||
#include <SoftRS485.h>
|
||||
|
||||
#define BUTTON 7
|
||||
|
||||
boolean state = LOW;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println(F("This is ReceiveDemo, version 0.1"));
|
||||
|
||||
init485(2,3,4,5); // library initialization:
|
||||
// connect pin 2 to RO of Max485
|
||||
// connect pin 3 to ^RE of Max485
|
||||
// connect pin 4 to DE of Max485
|
||||
// connect pin 5 to DI of Max485
|
||||
pinMode(BUTTON,INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
if (available485()) Serial.println("Received: "+get485message());
|
||||
|
||||
boolean new_state = digitalRead(BUTTON);
|
||||
if (new_state != state){
|
||||
if (state){
|
||||
for (int i=1; i<16; i++){
|
||||
String s = "Button pressed "+String(i);
|
||||
send485(s.c_str());
|
||||
delay(100);
|
||||
}
|
||||
} else send485("Button released!");
|
||||
state = new_state;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user