0 Members and 1 Guest are viewing this topic.
Sorry if this is difficult to follow, I didn't really know how to structure the diagram (if you want to call it a diagram). If you have any questions, just ask. Otherwise, I hope this helps!Code: [Select]SENDER RECEIVER¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯Pull ring lowRepeat up to [ARG 2]*8μs If ring is not low, abort | If tip is low, break from loop Pull tip lowIf tip is not low, abort Release tip Received byte = 0LOOP 8 TIMES LOOP 8 TIMES | Release ring, pull tip low | | Wait ~21μs | Wait until tip == ring | Rotate byte to send left | | If 0 rotated out, pull ring low | | If 1 rotated out, release tip | | Wait ~12μs | If tip is low, rotate 0 left into byte | | If tip is high, rotate 1 left into byteRelease tip and ring
SENDER RECEIVER¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯Pull ring lowRepeat up to [ARG 2]*8μs If ring is not low, abort | If tip is low, break from loop Pull tip lowIf tip is not low, abort Release tip Received byte = 0LOOP 8 TIMES LOOP 8 TIMES | Release ring, pull tip low | | Wait ~21μs | Wait until tip == ring | Rotate byte to send left | | If 0 rotated out, pull ring low | | If 1 rotated out, release tip | | Wait ~12μs | If tip is low, rotate 0 left into byte | | If tip is high, rotate 1 left into byteRelease tip and ring
Function get:If ring is low Pull down tip Delay Release tip Set byte to 0 by default Loop 8 times Wait until tip and ring are equal If tip is low bit received is 0 otherwise bit received is 1 Delay 12μs End of loopotherwiseReturn -1EndReturn received byte
Function send:Pull ring lowLoop until time runs out If tip is low, break from loopEnd loopIf time ran out Return -1;Loop 8 times Release ring pull down tip Delay 21μs If the bit is 1 pull ring low otherwise release tip Wait 12μsEnd of loopRelease tip and ring
void setup(){ pinMode(2,INPUT); pinMode(3,OUTPUT); digitalWrite(2,HIGH);//ring release digitalWrite(3,HIGH);//tip release Serial.begin(9600);}int Get(){ if (digitalRead(2)==LOW) { digitalWrite(3,LOW);//pull tip down delayMicroseconds(12); digitalWrite(3,HIGH);//release tip int recvbyte=0; for(int i=7; i>=0; i--){ while (digitalRead(2)!=digital Read(3)){}//wait until tip==ring if (digitalRead(2)==HIGH){ bitSet(recvbyte,i); } while (digitalRead(2)==digitalRead(3)){} } return recvbyte; } else { return 0; } }void loop(){ Serial.println(Get()); delay(1000);}