/* LED Dimmer By KB1UIF (A.Tedds) 2016 The circuit: Connect the LED from pin 9 to ground via a 200 Ohm current limiting Resistor. */ // the pin that the LED is connected to const int ledPin = 9; void setup() { // Initialize the serial communication: Serial.begin(9600); // Initialize the ledPin as an output: pinMode(ledPin, OUTPUT); // Send Instructions via the Serial Monitor: Serial.println("Enter an LED brightness value from 0 to 255 "); } void loop() { // check if any data has been sent from the computer: if (Serial.available()) { // Read the most recent input to serial monitor (which will be from 0 to 255): int brightness = Serial.parseInt(); // check that the input value is between 0 and 255: if (brightness >= 0 && brightness <= 255) { // set the brightness of the LED: analogWrite(ledPin, brightness); // Confirm the entered value on serial monitor screen: Serial.print("You entered a value of "); Serial.println(brightness); // repeat: } } }