Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <SoftwareSerial.h>
- #define LASER_INPUT_PIN 2 //aka D2
- #define TEMPERATURE_OUTPUT_PIN 5 //aka D5 PWM
- #define TEMPERATURE_BYTE_INDEX 4 // see https://i.imgur.com/AcpoeKa.png
- #define DEBUG //print temp value on serial con
- SoftwareSerial softSerial(LASER_INPUT_PIN, 3); // RX, TX
- byte laser_packet[7];
- byte index = 0U;
- void setup() {
- #ifdef DEBUG
- Serial.begin(9600);
- #endif
- softSerial.begin(200);
- pinMode(TEMPERATURE_OUTPUT_PIN, OUTPUT);
- }
- void loop() {
- //analogWrite(TEMPERATURE_OUTPUT_PIN, 170);
- while (softSerial.available() > 0) {
- byte b = softSerial.read();
- if (b == 0xFF) { //start of packet
- index = 0U;
- }
- laser_packet[index++] = b; //store byte
- }
- if (index == 7) {
- #ifdef DEBUG
- Serial.print("Temp: ");
- uint16_t temp = laser_packet[TEMPERATURE_BYTE_INDEX];
- Serial.print(temp);
- Serial.println("C");
- #endif
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement