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
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Gerber
|
||||
BIN
Nano845-2.fzz
Normal file
BIN
Nano845-2.fzz
Normal file
Binary file not shown.
BIN
Nano845.fzz
BIN
Nano845.fzz
Binary file not shown.
@@ -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++;
|
||||
|
||||
|
||||
@@ -8,14 +8,25 @@ int enable = 9;
|
||||
int sTx = 8;
|
||||
int sRx = 3;
|
||||
|
||||
long base = 100;
|
||||
// Für Controllino könnte man benutzen: sRx = 20, sTx = 21, enable = 53
|
||||
|
||||
int in1 = 4; // o
|
||||
int in2 = 5; // |o
|
||||
int in3 = 6; // ||o
|
||||
int in4 = 7; // |||o
|
||||
// ↓↓↓↓
|
||||
int irq = 2;// ←++++
|
||||
|
||||
long base = 1000;
|
||||
|
||||
int id = 0;
|
||||
int baud = 19200;
|
||||
int baud = 115200;
|
||||
char c;
|
||||
int counter = 0;
|
||||
bool reg1=false,reg2=false,reg3=false,reg4=false;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(baud);
|
||||
pinMode(A0,INPUT);
|
||||
id = analogRead(A0);
|
||||
|
||||
@@ -24,15 +35,30 @@ void setup(){
|
||||
|
||||
pinMode(sTx,OUTPUT);
|
||||
digitalWrite(sTx,LOW);
|
||||
|
||||
pinMode(in1,INPUT);
|
||||
pinMode(in2,INPUT);
|
||||
pinMode(in3,INPUT);
|
||||
pinMode(in4,INPUT);
|
||||
|
||||
pinMode(irq,INPUT);
|
||||
attachInterrupt(digitalPinToInterrupt(irq),interrupt,RISING);
|
||||
|
||||
pinMode(sRx,INPUT);
|
||||
Serial.begin(115200);
|
||||
Serial.print("Baud rate set to ");
|
||||
Serial.println(baud);
|
||||
Serial.print("Initialized Arduino #");
|
||||
Serial.println(id);
|
||||
}
|
||||
|
||||
void interrupt(){
|
||||
Serial.println("Interrupt");
|
||||
reg1 = digitalRead(in1);
|
||||
reg2 = digitalRead(in2);
|
||||
reg3 = digitalRead(in3);
|
||||
reg4 = digitalRead(in4);
|
||||
|
||||
}
|
||||
bool sendBit(bool bt){
|
||||
digitalWrite(sTx,bt);
|
||||
delayMicroseconds(80);
|
||||
@@ -83,11 +109,21 @@ bool sendString(String s){
|
||||
}
|
||||
|
||||
void loop(){
|
||||
counter++;
|
||||
String s = "Hier ist ";
|
||||
s.concat(id);
|
||||
s+=": counter = ";
|
||||
s.concat(counter);
|
||||
while (!sendString(s)) delay(10*base);
|
||||
delay(id);
|
||||
if (reg1){
|
||||
reg1 = false;
|
||||
sendString("t:02:01");
|
||||
}
|
||||
if (reg2){
|
||||
reg2 = false;
|
||||
sendString("t:02:02");
|
||||
}
|
||||
if (reg3){
|
||||
reg3 = false;
|
||||
sendString("t:02:03");
|
||||
}
|
||||
if (reg4){
|
||||
reg4 = false;
|
||||
sendString("t:02:04");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user