I am using a PWM function to control the brightness and the duty cycle . - 1 swi
ID: 3820931 • Letter: I
Question
I am using a PWM function to control the brightness and the duty cycle .
- 1 switch
- 2 * 10k -potentiometers , 1 for the brightness and another one will be used to control the rate .
Pic 24fGA102A . -Tricolor Led RGB using common cathode
You will find the schematic that I have drew below ( you can correct me if you want ) .
I am also using MPLABX for my software.
I am just doing steps 1 and 5 .
I am just doing steps 1 and 5 . si D4/ Vin1.2V 9-3 My £8! kM L35 kb - L61 Sal EAATIC DZAG2AD /-3-2-; Lrh T
Explanation / Answer
Uses button presses to switch an LED between off, dim, medium, and high brightness. */ // constants for this sketch const int buttonPin = 2; // pushbutton pin const int led = 9; // LED pin // variables for this sketch int ledMode = 1; // variable for recording button presses void setup() { // initialize the output pins: pinMode(led, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop() { // check if the pushbutton is pressed. if (digitalRead(buttonPin) == LOW) { // if it is, count a press ledMode = ledMode + 1; // if we've counted to an invalid mode if (ledMode == 5) { // reset to mode 1 ledMode = 1; } } // Detect the current mode and set the LED appropriately if (ledMode == 1) { //Mode 1 - LED is off digitalWrite(led, LOW); } else if (ledMode == 2) { //Mode 2 - LED is dim analogWrite(led, 64); } else if (ledMode == 3) { //Mode 3 - LED is medium analogWrite(led, 128); } else { //Mode 4 - LED is bright digitalWrite(led, HIGH); } } const int buttonPin = 8; // pushbutton pin const int led = 12; // LED pin // variables for this sketch int buttonPinMode = 1; // variable for recording button presses void setup() { // initialize the output pins: pinMode(led, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop() { digitalWrite(buttonPin,LOW); // check if the pushbutton is pressed. if (digitalRead(buttonPin)== LOW) return; if (digitalRead(buttonPin)==HIGH) { // if it is, count a press buttonPinMode = buttonPinMode + 1; // if we've counted to an invalid mode if (buttonPinMode == 5) { // reset to mode 1 buttonPinMode = 1; } } // Detect the current mode and set the LED appropriately if (buttonPinMode == 1) { //Mode 1 - LED is off digitalWrite(led, LOW); delay(200); } else if (buttonPinMode == 2) { //Mode 2 - LED is dim analogWrite(led, 64); delay(200); } else if (buttonPinMode == 3) { //Mode 3 - LED is medium analogWrite(led, 128); delay(200); } else { //Mode 4 - LED is bright digitalWrite(led, HIGH); delay(200); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.