I cannot seem to figure out why only the A3 pin is allowing me to output a value between 0-4095 and actually doing what I expect. All the other pins (A0-A5) do not output any voltage and as a result obviously do not light the LED.
I added the base code below. If I change the variable “ledPin” to any of the other analog pins 0-5 (other than A3) I get nothing.
According to the Photon datasheet A0-A7 should 12-bit GPIOs (among other things)…
int ledPin = A3;
int val = 0;
bool goingUp = true;
int brighten(int curVal){
return curVal + 20;
}
int darken(int curVal){
return curVal - 20;
}
void setup(){
pinMode(ledPin, OUTPUT);
}
void loop(){
Serial.begin();
if (goingUp) {
if (val > 4045) {
goingUp = false;
}
val = brighten(val);
} else {
if (val < 2400) {
goingUp = true;
}
val = darken(val);
}
analogWrite(ledPin, val);
Serial.println(val);
delay(10);
}
YES! Thank you @ScruffR, that’s exactly what I needed. I was buried in the docs but just didn’t read far enough down to get the link to the DAC piece. Thanks so much.
For anyone else that finds this thread, note that the code above is a DAC example and the code below is a PWM example. Differences are PWM PIN and PWM only steps from 0-255 not 0-4095 like DAC does.
int ledPin = D0;
int val = 0;
bool goingUp = true;
int brighten(int curVal){
return curVal + 3;
}
int darken(int curVal){
return curVal - 3;
}
void setup(){
pinMode(ledPin, OUTPUT);
}
void loop(){
Serial.begin();
if (goingUp) {
if (val > 255) {
goingUp = false;
}
val = brighten(val);
} else {
if (val < 0) {
goingUp = true;
}
val = darken(val);
}
analogWrite(ledPin, val);
Serial.println(val);
delay(10);
}