diff options
| author | Abel Tim <abel.tim.t@gmail.com> | 2026-02-08 14:09:12 +0100 |
|---|---|---|
| committer | Abel Tim <abel.tim.t@gmail.com> | 2026-02-08 14:09:12 +0100 |
| commit | 3d4372df3c0fd76fd78f7ba6dee02f678ffa51f2 (patch) | |
| tree | 68028bda5e90b2e2d4de0590b51c7c96d337a37d /code/debug/IR | |
| parent | 42dfd646a14c5d59fb5bf47c5453c6b7b64f63cf (diff) | |
| download | robotica-3d4372df3c0fd76fd78f7ba6dee02f678ffa51f2.tar.gz robotica-3d4372df3c0fd76fd78f7ba6dee02f678ffa51f2.zip | |
i am the only one who reads there anyways so why do i bother
imagen there is a butifull commit message here
_____________________________________
/ Nothing so needs reforming as other \
| people's habits. |
| |
\ -- Mark Twain /
-------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Diffstat (limited to 'code/debug/IR')
| -rw-r--r-- | code/debug/IR/IR-ONLY/IR-ONLY.ino | 72 | ||||
| -rw-r--r-- | code/debug/IR/XIAO/XIAO.ino | 74 | ||||
| -rw-r--r-- | code/debug/IR/cheapRCJ05sensors-RobotDemos09.pdf | bin | 0 -> 480338 bytes | |||
| -rw-r--r-- | code/debug/IR/teensy-read/teensy-read.ino | 30 |
4 files changed, 176 insertions, 0 deletions
diff --git a/code/debug/IR/IR-ONLY/IR-ONLY.ino b/code/debug/IR/IR-ONLY/IR-ONLY.ino new file mode 100644 index 0000000..31fb80b --- /dev/null +++ b/code/debug/IR/IR-ONLY/IR-ONLY.ino @@ -0,0 +1,72 @@ +//set pins + +int ir1 = 0; +int ir2 = 1; +int ir3 = 9; +int ir4 = 2; +int ir5 = 3; +int ir6 = 4; +int ir7 = 5; +int ir8 = 8; + +//arrays cus typing a lot is hard even with auto complete +int pins[8] = {ir1, ir2, ir3, ir4, ir5, ir6, ir7, ir8}; +volatile unsigned long startTime[8]; +volatile unsigned long pulseWidth[8]; + +void ISR0(); +void ISR1(); +void ISR2(); +void ISR3(); +void ISR4(); +void ISR5(); +void ISR6(); +void ISR7(); + +void setup() { + Serial.begin(9600); + + //pins setup + for (int i = 0; i < 8; i++) { + pinMode(pins[i], INPUT); + } + //attach interpts + attachInterrupt(digitalPinToInterrupt(ir1), ISR0, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir2), ISR1, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir3), ISR2, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir4), ISR3, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir5), ISR4, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir6), ISR5, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir7), ISR6, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir8), ISR7, CHANGE); +} + +void loop() { + noInterrupts(); + for (int i = 0; i < 8; i++) { + Serial.print("ir"); Serial.print(i + 1); + Serial.print(": "); Serial.print(pulseWidth[i]); Serial.print(" "); + } + Serial.println(); + interrupts(); + delay(200); +} + +//calc pulsewidth +void handlePWM(int idx) { + if (digitalRead(pins[idx]) == HIGH) { + startTime[idx] = micros(); + } else { + pulseWidth[idx] = micros() - startTime[idx]; + } +} + +//interupts +void ISR0() { handlePWM(0); } +void ISR1() { handlePWM(1); } +void ISR2() { handlePWM(2); } +void ISR3() { handlePWM(3); } +void ISR4() { handlePWM(4); } +void ISR5() { handlePWM(5); } +void ISR6() { handlePWM(6); } +void ISR7() { handlePWM(7); } diff --git a/code/debug/IR/XIAO/XIAO.ino b/code/debug/IR/XIAO/XIAO.ino new file mode 100644 index 0000000..67d27c4 --- /dev/null +++ b/code/debug/IR/XIAO/XIAO.ino @@ -0,0 +1,74 @@ + +//set pins +int ir1 = 0; +int ir2 = 1; +int ir3 = 9; +int ir4 = 2; +int ir5 = 3; +int ir6 = 4; +int ir7 = 5; +int ir8 = 8; + +//arrays cus typing a lot is hard even with auto complete +int pins[8] = {ir1, ir2, ir3, ir4, ir5, ir6, ir7, ir8}; +volatile unsigned long startTime[8]; +volatile unsigned long pulseWidth[8]; + +void ISR0(); +void ISR1(); +void ISR2(); +void ISR3(); +void ISR4(); +void ISR5(); +void ISR6(); +void ISR7(); + +void setup() { + Serial.begin(9600); + Serial1.begin(75); + + //pins setup + for (int i = 0; i < 8; i++) { + pinMode(pins[i], INPUT); + } + //attach interpts + attachInterrupt(digitalPinToInterrupt(ir1), ISR0, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir2), ISR1, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir3), ISR2, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir4), ISR3, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir5), ISR4, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir6), ISR5, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir7), ISR6, CHANGE); + attachInterrupt(digitalPinToInterrupt(ir8), ISR7, CHANGE); +} + +void loop() { + noInterrupts(); + //for (int i = 0; i < 8; i++) { + // Serial.print("ir"); Serial.print(i + 1); + // Serial.print(": "); Serial.print(pulseWidth[i]); Serial.print(" "); + //} + //Serial.println(); + Serial1.println(pulseWidth[8]); + interrupts(); + delay(200); +} + +//calc pulsewidth +void handlePWM(int idx) { + if (digitalRead(pins[idx]) == HIGH) { + startTime[idx] = micros(); + } else { + pulseWidth[idx] = micros() - startTime[idx]; + } +} + +//interupts +void ISR0() { handlePWM(0); } +void ISR1() { handlePWM(1); } +void ISR2() { handlePWM(2); } +void ISR3() { handlePWM(3); } +void ISR4() { handlePWM(4); } +void ISR5() { handlePWM(5); } +void ISR6() { handlePWM(6); } +void ISR7() { handlePWM(7); } diff --git a/code/debug/IR/cheapRCJ05sensors-RobotDemos09.pdf b/code/debug/IR/cheapRCJ05sensors-RobotDemos09.pdf Binary files differnew file mode 100644 index 0000000..3eed27d --- /dev/null +++ b/code/debug/IR/cheapRCJ05sensors-RobotDemos09.pdf diff --git a/code/debug/IR/teensy-read/teensy-read.ino b/code/debug/IR/teensy-read/teensy-read.ino new file mode 100644 index 0000000..6ce767b --- /dev/null +++ b/code/debug/IR/teensy-read/teensy-read.ino @@ -0,0 +1,30 @@ +int incomingByte = 0; // for incoming serial data + +void setup() { + Serial.begin(9600); + Serial1.begin(75); + Serial2.begin(75); + +} + +// _________________________________________ +// / fucking mixes the signal and prints but \ +// | dont know recieve format yet so keeping | +// \ it here / +// ----------------------------------------- +// \ ^__^ +// \ (oo)\_______ +// (__)\ )\/\ +// ||----w | +// || || + +void loop() { + if (Serial1.available() > 0) { + incomingByte = Serial.read(); + Serial.println(incomingByte, DEC); + } + if (Serial2.available() > 0) { + incomingByte = Serial.read(); + Serial.println(incomingByte, DEC); + } +}
\ No newline at end of file |
