Skip to content

Instantly share code, notes, and snippets.

@KameronKeller
Last active October 13, 2022 03:41
Show Gist options
  • Save KameronKeller/aa3399ae547699e9c31fe40fab3b66e2 to your computer and use it in GitHub Desktop.
Save KameronKeller/aa3399ae547699e9c31fe40fab3b66e2 to your computer and use it in GitHub Desktop.
#define LASER_PIN (4)
#define SEND_DELAY (4)
void setup() {
pinMode(LASER_PIN, OUTPUT);
Serial.begin(9600);
sendByte(0x7);
}
void loop() {
while(Serial.available()) {
char msg = Serial.read();
Serial.write(msg);
sendByte(msg);
}
}
void sendString(String str) {
for(int i = 0; i < str.length(); i++) {
sendByte(str.charAt(i));
}
}
void sendByte(char byte_to_send) {
digitalWrite(LASER_PIN, HIGH);
delay(SEND_DELAY);
for(int i = 0; i < 8; i++) {
char bit_value = (byte_to_send >> i) & 1;
digitalWrite(LASER_PIN, bit_value ? HIGH : LOW);
delay(SEND_DELAY);
}
digitalWrite(LASER_PIN, LOW);
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment