Skip to content
Snippets Groups Projects
Commit 189a36bf authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

wip

parent 6ba60822
Branches
No related tags found
No related merge requests found
#
# FTF.hop.py
#
# (c) MIT CBA Neil Gershenfeld 12/23/23
#
import serial,sys,time
#
port = sys.argv[1]
ser = serial.Serial(port,921600)
ser.flush()
#
ser.write(bytearray([ord('a'),0]))
print(f"found {1+int.from_bytes(ser.read(),'big')} nodes")
while True:
ser.write(bytearray([ord('l'),0,0b111]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),0,0b110]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),0,0b100]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),0,0b000]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),1,0b111]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),1,0b110]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),1,0b100]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),1,0b000]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),2,0b111]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),2,0b110]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),2,0b100]))
time.sleep(0.1)
ser.write(bytearray([ord('l'),2,0b000]))
time.sleep(0.1)
ser.write(bytearray([ord('L'),0b111]))
time.sleep(0.2)
ser.write(bytearray([ord('L'),0b000]))
time.sleep(0.2)
ser.write(bytearray([ord('L'),0b111]))
time.sleep(0.2)
ser.write(bytearray([ord('L'),0b000]))
time.sleep(0.2)
ser.write(bytearray([ord('L'),0b111]))
time.sleep(0.2)
This diff is collapsed.
//
// FTF.hop.LED.t1624.ino
//
// (c) MIT CBA Neil Gershenfeld 7/4/23
//
#define LED1 1
#define LED2 2
#define LED3 3
#define RxOut 4
#define PortIn Serial1
#define PortOut Serial
char cmd;
uint8_t arg,addr,address;
void setup() {
delay(1000);
PortIn.begin(921600);
PortOut.begin(921600);
digitalWriteFast(LED1,LOW);
digitalWriteFast(LED2,LOW);
digitalWriteFast(LED3,LOW);
pinMode(LED1,INPUT);
pinMode(LED2,INPUT);
pinMode(LED3,INPUT);
}
void loop() {
//
// check input port
//
if (PortIn.available() != 0) {
//
// read and forward command
//
cmd = PortIn.read();
PortOut.write(cmd);
//
// all LED command?
//
if (cmd == 'L') {
//
// read and forward argument
//
while (PortIn.available() == 0);
arg = PortIn.read();
PortOut.write(arg);
if (arg & 0b1)
pinMode(LED1,INPUT);
else
pinMode(LED1,OUTPUT);
if (arg & 0b10)
pinMode(LED2,INPUT);
else
pinMode(LED2,OUTPUT);
if (arg & 0b100)
pinMode(LED3,INPUT);
else
pinMode(LED3,OUTPUT);
}
//
// individual LED command?
//
else if (cmd == 'l') {
//
// read and forward address and argument
//
while (PortIn.available() == 0);
addr = PortIn.read();
PortOut.write(addr);
while (PortIn.available() == 0);
arg = PortIn.read();
PortOut.write(arg);
if (addr == address) {
if (arg & 0b1)
pinMode(LED1,INPUT);
else
pinMode(LED1,OUTPUT);
if (arg & 0b10)
pinMode(LED2,INPUT);
else
pinMode(LED2,OUTPUT);
if (arg & 0b100)
pinMode(LED3,INPUT);
else
pinMode(LED3,OUTPUT);
}
}
//
// address assignment command?
//
else if (cmd == 'a') {
//
// read address
//
while (PortIn.available() == 0);
address = PortIn.read();
//
// last node?
//
if (digitalRead(RxOut) == LOW) {
//
// yes, send back count
//
PortIn.write(address);
}
else {
//
// no, increment and forward address
//
PortOut.write(address+1);
}
}
}
//
// check output port
//
if (PortOut.available() != 0) {
//
// send to input port
//
PortIn.write(PortOut.read());
}
}
networking_communications/hop/hello.hop-LED.t1624.interior.png

6.49 KiB

networking_communications/hop/hello.hop-LED.t1624.jpg

489 KiB

File added
networking_communications/hop/hello.hop-LED.t1624.png

24.5 KiB

networking_communications/hop/hello.hop-LED.t1624.top.png

9.26 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment