Skip to content

Commit 2268291

Browse files
MiKfbraghiroli
authored andcommitted
Added PWM control for RGB Led and an example to test it
1 parent 12436fc commit 2268291

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Shows The PWM functionalities on the RGB Led
3+
4+
created 18 Jun 2015
5+
6+
7+
*/
8+
9+
#include <Arduino.h>
10+
11+
long randNumberR, randNumberG, randNumberB;
12+
13+
void setup(){
14+
randomSeed(analogRead(0));
15+
}
16+
17+
void loop(){
18+
randNumberR = random(128);
19+
randNumberG = random(128);
20+
randNumberB = random(128);
21+
22+
23+
24+
ledGreenLight(randNumberG);
25+
ledBlueLight(randNumberB);
26+
ledRedLight(randNumberR);
27+
28+
delay(500);
29+
}

hardware/AMEL/samd/variants/AMEL_SmartEverything/variant.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ void ledGreenLight(uint32_t value) {
279279
} else if (value == LOW) {
280280
digitalWrite(PIN_LED_GREEN, HIGH);
281281
} else {
282-
digitalWrite(PIN_LED_GREEN, 255-value); // in case of PWM
282+
analogWrite(PIN_LED_GREEN, 255-value); // in case of PWM
283283
}
284284
}
285285

@@ -289,7 +289,7 @@ void ledRedLight(uint32_t value) {
289289
} else if (value == LOW) {
290290
digitalWrite(PIN_LED_RED, HIGH);
291291
} else {
292-
digitalWrite(PIN_LED_RED, 255-value); // in case of PWM
292+
analogWrite(PIN_LED_RED, 255-value); // in case of PWM
293293
}
294294
}
295295

@@ -299,7 +299,7 @@ void ledBlueLight(uint32_t value) {
299299
} else if (value == LOW) {
300300
digitalWrite(PIN_LED_BLUE, HIGH);
301301
} else {
302-
digitalWrite(PIN_LED_BLUE, 255-value); // in case of PWM
302+
analogWrite(PIN_LED_BLUE, 255-value); // in case of PWM
303303
}
304304
}
305305

0 commit comments

Comments
 (0)