#include #define IROUTPUTPIN D0 // IR diode on my custom PCB // Made for RP2040 #define NEOPOWERPIN 11 // Provides voltage for the built-in NeoPixel #define NEOPIXELPIN 12 // Datapin for the the built-in NeoPixel #define NUMPIXELS 1 //Amount of NeoPixels Adafruit_NeoPixel pixel(NUMPIXELS, NEOPIXELPIN, NEO_RGB + NEO_KHZ800); #define DELAYVAL 100 bool led_on = false; void setup() { pinMode(LED_BUILTIN, OUTPUT); // Initialize digital pin LED_BUILTIN as an output. pinMode(IROUTPUTPIN, OUTPUT); // Initialize the IR pin as an output. pinMode(NEOPOWERPIN, OUTPUT); // Initialize digital pin NEOPOWERPIN as an output. digitalWrite(NEOPOWERPIN, HIGH); // Power for the NeoPixel pixel.begin(); Serial.begin(9600); } void loop() { if (Serial.available()) { char char_in = Serial.read(); // Read one character //Serial.write(char_in); // Return the character for debug if (char_in == '1') { // Turn led on pixel.clear(); pixel.setPixelColor(0, 150,100,50); pixel.show(); led_on = true; Serial.println("LED,0,1"); // Send confirm } else if (char_in == '0') { // Turn led off pixel.clear(); pixel.show(); led_on = false; Serial.println("LED,0,0"); // Send confirm } else if (char_in == '\n') { // Send status of the led if (led_on) { Serial.println("LED,0,1"); } else { Serial.println("LED,0,0"); } } else { // Blink only the small built-led digitalWrite(LED_BUILTIN, LOW); delay(DELAYVAL); digitalWrite(LED_BUILTIN, HIGH); Serial.println("Not recognised"); } } delay(DELAYVAL); /* To meet the requirements, I added this to blink the IR led I have on the PCB I made in week 8. */ if (!led_on) { digitalWrite(IROUTPUTPIN, !digitalRead(IROUTPUTPIN)); } }