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 sTx = 2;
|
||||||
int sRx = 3;
|
int sRx = 3;
|
||||||
|
|
||||||
@@ -13,34 +15,34 @@ String message;
|
|||||||
void setup(){
|
void setup(){
|
||||||
pinMode(sRx,INPUT);
|
pinMode(sRx,INPUT);
|
||||||
pinMode(sTx,OUTPUT);
|
pinMode(sTx,OUTPUT);
|
||||||
attachInterrupt(digitalPinToInterrupt(sRx),change,CHANGE);
|
attachInterrupt(digitalPinToInterrupt(sRx),change485,CHANGE);
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Receiver ready");
|
Serial.println("Receiver ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset(long dif){
|
void reset485(long dif){
|
||||||
rcv = 0;
|
rcv = 0;
|
||||||
idx = -1;
|
idx = -1;
|
||||||
message.reserve(32);
|
message.reserve(32);
|
||||||
}
|
}
|
||||||
void change(){
|
void change485(){
|
||||||
bool bt = digitalRead(sRx);
|
bool bt = digitalRead(sRx);
|
||||||
now = micros();
|
now = micros();
|
||||||
dif = now - lt;
|
dif = now - lt;
|
||||||
lt = now;
|
lt = now;
|
||||||
if (dif > rst){
|
if (dif > rst){
|
||||||
reset(dif);
|
reset485(dif);
|
||||||
} else {
|
} else {
|
||||||
handle(!bt,dif);
|
handle485(!bt,dif);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle(boolean bt, long dif){
|
void handle485(boolean bt, long dif){
|
||||||
long count = dif/base;
|
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;
|
if (idx>=0) rcv |= bt<<idx;
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,25 @@ int enable = 9;
|
|||||||
int sTx = 8;
|
int sTx = 8;
|
||||||
int sRx = 3;
|
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 id = 0;
|
||||||
int baud = 19200;
|
int baud = 115200;
|
||||||
char c;
|
char c;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
bool reg1=false,reg2=false,reg3=false,reg4=false;
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
|
Serial.begin(baud);
|
||||||
pinMode(A0,INPUT);
|
pinMode(A0,INPUT);
|
||||||
id = analogRead(A0);
|
id = analogRead(A0);
|
||||||
|
|
||||||
@@ -24,15 +35,30 @@ void setup(){
|
|||||||
|
|
||||||
pinMode(sTx,OUTPUT);
|
pinMode(sTx,OUTPUT);
|
||||||
digitalWrite(sTx,LOW);
|
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);
|
pinMode(sRx,INPUT);
|
||||||
Serial.begin(115200);
|
|
||||||
Serial.print("Baud rate set to ");
|
Serial.print("Baud rate set to ");
|
||||||
Serial.println(baud);
|
Serial.println(baud);
|
||||||
Serial.print("Initialized Arduino #");
|
Serial.print("Initialized Arduino #");
|
||||||
Serial.println(id);
|
Serial.println(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void interrupt(){
|
||||||
|
Serial.println("Interrupt");
|
||||||
|
reg1 = digitalRead(in1);
|
||||||
|
reg2 = digitalRead(in2);
|
||||||
|
reg3 = digitalRead(in3);
|
||||||
|
reg4 = digitalRead(in4);
|
||||||
|
|
||||||
|
}
|
||||||
bool sendBit(bool bt){
|
bool sendBit(bool bt){
|
||||||
digitalWrite(sTx,bt);
|
digitalWrite(sTx,bt);
|
||||||
delayMicroseconds(80);
|
delayMicroseconds(80);
|
||||||
@@ -83,11 +109,21 @@ bool sendString(String s){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
counter++;
|
if (reg1){
|
||||||
String s = "Hier ist ";
|
reg1 = false;
|
||||||
s.concat(id);
|
sendString("t:02:01");
|
||||||
s+=": counter = ";
|
}
|
||||||
s.concat(counter);
|
if (reg2){
|
||||||
while (!sendString(s)) delay(10*base);
|
reg2 = false;
|
||||||
delay(id);
|
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