summaryrefslogtreecommitdiff
path: root/CODE/debug/IR/teensydeco/teensydeco.ino
diff options
context:
space:
mode:
authorAbel Tim <abel@abel-ms7c95.home>2025-03-20 20:56:07 +0100
committerAbel Tim <abel@abel-ms7c95.home>2025-03-20 20:56:07 +0100
commit6a09f9de806bdde037010bff3535627c0e9f62d9 (patch)
treed91b8736598308e5574932cfe392caa42c4b486f /CODE/debug/IR/teensydeco/teensydeco.ino
parentd4a5a8e430abccc7a08861654dac21ecec3eeb3d (diff)
downloadrobotica-6a09f9de806bdde037010bff3535627c0e9f62d9.tar.gz
robotica-6a09f9de806bdde037010bff3535627c0e9f62d9.zip
able to convert ir signal into degrees
Diffstat (limited to 'CODE/debug/IR/teensydeco/teensydeco.ino')
-rw-r--r--CODE/debug/IR/teensydeco/teensydeco.ino101
1 files changed, 101 insertions, 0 deletions
diff --git a/CODE/debug/IR/teensydeco/teensydeco.ino b/CODE/debug/IR/teensydeco/teensydeco.ino
new file mode 100644
index 0000000..87828be
--- /dev/null
+++ b/CODE/debug/IR/teensydeco/teensydeco.ino
@@ -0,0 +1,101 @@
+int incomingbyte1 = 0; //the byte that it is reciefing
+bool iswriting1 = false; //true if writing else fals
+String tlocdat1 = ""; //temporary location data
+String locdat1 = ""; //location data
+int nir1 = "-99"; // which ir sensor it is
+int pir1 = "-99"; // amount of pulses it had
+
+int incomingbyte2 = 0; //same but for seeed xiao N 2
+bool iswriting2 = false;
+String tlocdat2 = "";
+String locdat2 = "";
+int nir2 = "-99";
+int pir2 = "-99";
+
+float degwhere = -99.0; // where the ball is in degrees
+
+void setup() {
+ Serial.begin(9600);
+ Serial1.begin(9600);
+ Serial2.begin(9600);
+}
+
+void loop() {
+ if (Serial1.available() > 0) {
+ incomingbyte1 = Serial1.read();
+ //Serial.print(char(incomingbyte1));
+ if (incomingbyte1 == 's'){
+ iswriting1 = true;
+ tlocdat1 = "";
+ }else if(incomingbyte1 == 'e'){
+ iswriting1 = false;
+ locdat1 = tlocdat1;
+ }else if(iswriting1 == true){
+ //Serial.print(char(incomingbyte1));
+ tlocdat1 += (char)incomingbyte1;
+ }
+ }
+ if (Serial2.available() > 0) {
+ incomingbyte2 = Serial2.read();
+ //Serial.print(char(incomingbyte2));
+ if (incomingbyte2 == 's'){
+ iswriting2 = true;
+ tlocdat2 = "";
+ }else if(incomingbyte1 == 'e'){
+ iswriting2 = false;
+ locdat2 = tlocdat1;
+ }else if(iswriting2 == true){
+ //Serial.print(char(incomingbyte1));
+ tlocdat2 += (char)incomingbyte1;
+ }
+ }
+ //Serial.println(locdat);
+ sscanf(locdat1.c_str(), "%d, %d", &nir1, &pir1);
+ sscanf(locdat2.c_str(), "%d, %d", &nir2, &pir2);
+
+
+ if(pir1 > pir2){
+ if(nir1 = 1){ //not good looking code because posbile wrong wireing
+ degwhere = 0;
+ }else if(nir1 = 2){
+ degwhere = 22.5;
+ }else if(nir1 = 3){
+ degwhere = 45;
+ }else if(nir1 = 4){
+ degwhere = 67.5;
+ }else if(nir1 = 5){
+ degwhere = 90;
+ }else if(nir1 = 6){
+ degwhere = 112.5;
+ }else if(nir1 = 7){
+ degwhere = 135;
+ }else if(nir1 = 8){
+ degwhere = 157.5;
+ }
+ }else{
+ if(nir2 = 1){
+ degwhere = 180;
+ }else if(nir2 = 2){
+ degwhere = 202.5;
+ }else if(nir2 = 3){
+ degwhere = 225;
+ }else if(nir2 = 4){
+ degwhere = 247.5;
+ }else if(nir2 = 5){
+ degwhere = 270;
+ }else if(nir2 = 6){
+ degwhere = 292.5;
+ }else if(nir2 = 7){
+ degwhere = 315;
+ }else if(nir2 = 8){
+ degwhere = 337.5;
+ }
+ }
+
+ Serial.print("IR sensor N: ");
+ Serial.print(nir1);
+ Serial.print(", with ");
+ Serial.print(pir1);
+ Serial.println(" pulses.");
+ delay(10);
+}