First, off I am Brand new to Arduino let alone programming.
I'm trying to make a simple program that takes to analog volt potentiometers and outputs PWM to two LEDs. I found a code that does the with one. I edited it to try to make it do two LEDs. The problem I'm having it is saying 'LEDpin2" was not declared in this scope. What am I missing?
int potPin = A0; //Declare potPin to be analog pin A0
int LEDPin1 = 9; // Declare LEDPin to be arduino pin 9
int potPin1 = A1; //Declare potPin to be analog pin A0
int LEDPin2 = 10; // Declare LEDPin to be arduino pin 10
int readValue; // Use this variable to read Potentiometer 1
int writeValue; // Use this variable for writing to LED 1
int readValue1; // Use this variable to read Potentiometer 2
int writeValue1; // Use this variable for writing to LED 2
void setup() {
pinMode(potPin, INPUT); //set potPin to be an input
pinMode(potPin1, INPUT); //set potPin1 to be an input
pinMode(LEDPin1, OUTPUT); //set LEDPin to be an OUTPUT
pinMode(LEDPin2, OUTPUT); //set LEDPin to be an OUTPUT
Serial.begin(9600); // turn on Serial Port
}
void loop() {
readValue = analogRead(potPin); //Read the voltage on the Potentiometer 1
readValue1 = analogRead(potPin1); //Read the voltage on the Potentiometer 2
writeValue = (255. / 1023.) * readValue;
writeValue1 = (255. / 1023.) * readValue1; //Calculate Write Value for LED
analogWrite(LEDPin1, writeValue); //Write to the LED 1
analogWrite(LEDPin2, writeValue1); //Write to the LED 2
Serial.print("You are writing a value of "); //for debugging print your values
Serial.println(writeValue);
}
Also, LED1 has a flicker at a lower voltage when I check everything on the LEDs with the original knob it was operating at 2.0 kHz is it possible for the Arduino to do this?
If you wish to continue using this resource, please go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon. In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window.
It is inappropriate to attach it as a ".ino" file. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.
But don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code", it can be quite garbled and is always more difficult to read. It think you already did, but posted as you have it is by no means obvious.
Also tidy up your blank space. Use blank lines only between functional blocks.
It is inappropriate to attach it as a ".ino" file. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.
Most forum members, I suspect, read the forum on smartphones and tablets most of the time. On these devices you cannot open a .ino file. Maybe they could download an app to view them, but this would not be necessary if whoever asks a question posts their code using code tags, as they are encouraged to do in the forum guide (which, of course, they will have read before they make their first post, won't they?).
But forum posts have a limit to the number of characters, and posting long pieces of code could exceed that limit and can't be posted that way. When this happens, the poster should think to themselves "Will anyone want to read such a long piece of code? Maybe I should make it shorter by removing all the parts that are not relavent to my problem". Often, by making the code short enough to post in code tags, the poster finds the error themselves.
But sometimes the shorter version of the code works and the full version does not, and the poster cannot figure out why. In this situation, attaching the large version as a .ino is the only option.
People reading through see something as an attachment? What are they going to do with an attachment? What happens to an attachment in an iPad?
What happens when you click in an attachment? Depends on what the browser is configured to do with it. If you do not have the Arduino IDE installed, you will likely get a menu asking you what to do, so what do you pick?
If you do have the IDE installed on a PC, then the IDE has configured the system to open the IDE and load that file. That may be convenient, or it may not be; this is somewhat of a personal preference and people do not like to be so constrained.
If however, the code is posted as advised (may however not be possible with large code) then it just shows up as part of the Web page and people can read it and deal with it easily as they choose.