Skip to content

Commit

Permalink
Update Dimmer.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmdaliab authored Dec 29, 2023
1 parent fdbfc5b commit 14b6c62
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions examples/04.Communication/Dimmer/Dimmer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ void setup() {
}

void loop() {
byte brightness;
char num[4] = "!!!!";
byte brightness = 0;

// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
Serial.readBytesUntil('\n', num, 4);
// calculate brightness
for(int i = 0; num[i] != '!'; i++){
brightness = brightness * 10 + num[i] - 48;
}
// set the brightness of the LED:
analogWrite(ledPin, brightness);
}
Expand Down

0 comments on commit 14b6c62

Please sign in to comment.