Hello all,
Please help me out, I am new to this arduino and code. I was trying to built a dimming (log - dimming) using PWM output of arduino. Dimming effect will be control by two pushbutton, one for increment and other one decrement of brightness. After uploading the TX LED also gets OFF and serial port also not showing any activity when pushbutton is high. Please help with code.
const int LEDPin = 3; //set LED to pin to 3
const int BP1 = 2; //set Button 1 to pin2
const int BP2 = 7; //set Button 2 to pin 7
float DC = 0; //Set initial value of Duty Cycle to zero
int PushButton1 = 0; //inital value of push button 1 is set to zero
int PushButton2 = 0; //inital value of push button 2 is set to zero
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //turn on the serial port
pinMode(LEDPin, OUTPUT); //set LEDpin to be output
pinMode(BP1, INPUT); //set Button1 to be input
pinMode(BP2, INPUT); //set Button2 to be input
}
void loop() {
// put your main code here, to run repeatedly:
DC = pow(1.5864,PushButton1)-1; //formula for duty cycle
if (PushButton1 == 1) { //press push button1
for (int PushButton1=0; PushButton1 <= 10; PushButton1++){ //condition for LED with Button1
analogWrite(LEDPin,DC); //write to LEDPin BV value
Serial.println("Button1 is Pressed"); //Print to serial port
Serial.println("DC"); //print the value of DC
}
}
DC = pow(1.5864,PushButton2)-1; //formula for duty cycle
if (PushButton2 == 1) { //press push button2
for (int PushButton2=0; PushButton2 >= 0; PushButton2--){ //condition for LED with Button2
analogWrite(LEDPin,DC); //write to LEDPin BV value
Serial.println("Button2 is Pressed"); //Print to serial port
Serial.println("DC"); //print the value of DC
}
}
}