I am driving the digital outputs (LEDs switching on one by one as the voltage on A0 increases. This works fine for the I/Os 2, 4, 7, 8, 12 and 13. Using the I/Os 0, 1, 2, 3, , 5, 6, 9, 10 and 11 do not show the expected result. Do I need different shield commands to drive those PWM outputs?
Anyone's assistance is appreciated. Thanks. Hans
I moved your topic to an appropriate forum category @hansgubler.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
what is different?
why are you using the RX pin, 0, which is used to program the board?
Avoid using pins 0 and 1 if at all possible.
Please post your sketch that shows this problem
No.
All PWM pins can be used like normal I/O pins. But all I/O pins can't be used as PWM pins.
never use pins 0 & 1 without knowing what you are doing
This is because they are already wired to the TX & RX serial data pins.
Thanks for this message
Here is the sketch I am using:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int digitalOutPin1 = 0; // Analog output pin that the LED is attached to
const int digitalOutPin2 = 1; // Analog output pin that the LED is attached to
const int digitalOutPin3 = 2; // Analog output pin that the LED is attached to
const int digitalOutPin4 = 4; // Analog output pin that the LED is attached to
const int digitalOutPin5 = 7; // Analog output pin that the LED is attached to
const int digitalOutPin6 = 8; // Analog output pin that the LED is attached to
const int digitalOutPin7 = 12; // Analog output pin that the LED is attached to
const int digitalOutPin8 = 13; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue1 = 0; // value output to the PWM (analog out)
int outputValue2 = 0; // value output to the PWM (analog out)
int outputValue3 = 0; // value output to the PWM (analog out)
int outputValue4 = 0; // value output to the PWM (analog out)
int outputValue5 = 0; // value output to the PWM (analog out)
int outputValue6 = 0; // value output to the PWM (analog out)
int outputValue7 = 0; // value output to the PWM (analog out)
int outputValue8 = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue1 = map (sensorValue, 0, 600, 0, 233);
outputValue2 = map (sensorValue, 0, 600, 0, 233);
outputValue3 = map (sensorValue, 0, 600, 0, 233);
outputValue4 = map (sensorValue, 0, 800, 0, 233);
outputValue5 = map (sensorValue, 0, 1000, 0, 233);
outputValue6 = map (sensorValue, 0, 1200, 0, 233);
outputValue7 = map (sensorValue, 0, 1400, 0, 233);
outputValue8 = map (sensorValue, 0, 1600, 0, 233);
// change the analog out value:
analogWrite(digitalOutPin1, outputValue1);
analogWrite(digitalOutPin2, outputValue2);
analogWrite(digitalOutPin3, outputValue3);
analogWrite(digitalOutPin4, outputValue4);
analogWrite(digitalOutPin5, outputValue5);
analogWrite(digitalOutPin6, outputValue6);
analogWrite(digitalOutPin7, outputValue7);
analogWrite(digitalOutPin8, outputValue8);
// print the results to the Serial Monitor:
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue1);
Serial.println(outputValue2);
Serial.println(outputValue3);
Serial.println(outputValue4);
Serial.println(outputValue5);
Serial.println(outputValue6);
Serial.println(outputValue7);
Serial.println(outputValue8);
// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(2);
}
const int digitalOutPin1 = 0; // Analog output pin that the LED is attached to
const int digitalOutPin2 = 1; // Analog output pin that the LED is attached to
const int digitalOutPin3 = 2; // Analog output pin that the LED is attached to
const int digitalOutPin4 = 4; // Analog output pin that the LED is attached to
const int digitalOutPin5 = 7; // Analog output pin that the LED is attached to
const int digitalOutPin6 = 8; // Analog output pin that the LED is attached to
const int digitalOutPin7 = 12; // Analog output pin that the LED is attached to
const int digitalOutPin8 = 13; // Analog output pin that the LED is attached to
analogWrite() only works with PWM capable pins. How many of those pins are PWM capable ?
I am amused by the names that you gave them bearing in mind the comments
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.