Programming not working / serial interfacing not working

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
}
}
}

Let's start with the basics

You are not reading the state of the inputs anywhere in the code

The basics is actually to learn how to post code on the forum :wink:

OP, please read the sticky "how to use the forum", specifically the part about posting code.

I also suspect that your second for loop is not doing what you think it should be doing.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R
Planning and Implementing a Program

int PushButton1 = 0;        //inital value of push button 1 is set to zero
if (PushButton1 == 1) {         //press push button1

Well, that's a pretty silly test, don't you think?

DC = pow(1.5864,PushButton1)-1; //formula for duty cycle

1.58640 is what?

for (int PushButton1=0; PushButton1 <= 10; PushButton1++){        //condition for LED with Button1

This is my brother Darryl and my other brother Darryl. Why do you now have two variables named PushButton1?

  Serial.println("Button1 is Pressed");  //Print to serial port

That would be a lie, because the condition which this statement is executed has NOTHING to do with the state of any switch or pin.