neue Version der Leiterplatte fertiggestellt:
- jetzt mit 8 Optokoppler-Eingängen - zusätzlich mit 8-Pin-Header für weitere Peripherie Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Für Controllino könnte man benutzen: sRx = 20, sTx = 21, enable = 53
|
||||
|
||||
int sTx = 2;
|
||||
int sRx = 3;
|
||||
|
||||
@@ -13,34 +15,34 @@ String message;
|
||||
void setup(){
|
||||
pinMode(sRx,INPUT);
|
||||
pinMode(sTx,OUTPUT);
|
||||
attachInterrupt(digitalPinToInterrupt(sRx),change,CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(sRx),change485,CHANGE);
|
||||
Serial.begin(115200);
|
||||
Serial.println("Receiver ready");
|
||||
}
|
||||
|
||||
void reset(long dif){
|
||||
void reset485(long dif){
|
||||
rcv = 0;
|
||||
idx = -1;
|
||||
message.reserve(32);
|
||||
}
|
||||
void change(){
|
||||
void change485(){
|
||||
bool bt = digitalRead(sRx);
|
||||
now = micros();
|
||||
dif = now - lt;
|
||||
lt = now;
|
||||
if (dif > rst){
|
||||
reset(dif);
|
||||
reset485(dif);
|
||||
} else {
|
||||
handle(!bt,dif);
|
||||
handle485(!bt,dif);
|
||||
}
|
||||
}
|
||||
|
||||
void handle(boolean bt, long dif){
|
||||
void handle485(boolean bt, long dif){
|
||||
long count = dif/base;
|
||||
for (int i=0; i<count; i++) push(bt);
|
||||
for (int i=0; i<count; i++) push485(bt);
|
||||
}
|
||||
|
||||
void push(boolean bt){
|
||||
void push485(boolean bt){
|
||||
if (idx>=0) rcv |= bt<<idx;
|
||||
idx++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user