THIS WILL ONLY WORK ON PINS 3,5,6,9,10,11 (The ones with ~ under them)
analogWrite()
DescriptionWrites an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite() on the same pin). The frequency of the PWM signal is approximately 490 Hz.
The analogWrite function has nothing whatsoever to do with the analog pins
analogWrite(pin, value)
Parameters:
example
int bright=0;
void setup(){
pinMode(3,OUTPUT);
pinMode(5,OUTPUT);
}
void loop(){
analogWrite(3,bright);
digitalWrite(5,HIGH);
bright++;
if(bright>255){
bright=0;
}
}
This will increase the brightness of the LED attached to pin 3 slowly and then reset it onces it gets to full brightness. While the LED attached to pin 5 will be constantly on.
analogWrite()
DescriptionWrites an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite() on the same pin). The frequency of the PWM signal is approximately 490 Hz.
The analogWrite function has nothing whatsoever to do with the analog pins
analogWrite(pin, value)
Parameters:
- pin, the pin to write to.
- value: the duty cycle: between 0 (always off) and 255 (always on).
example
int bright=0;
void setup(){
pinMode(3,OUTPUT);
pinMode(5,OUTPUT);
}
void loop(){
analogWrite(3,bright);
digitalWrite(5,HIGH);
bright++;
if(bright>255){
bright=0;
}
}
This will increase the brightness of the LED attached to pin 3 slowly and then reset it onces it gets to full brightness. While the LED attached to pin 5 will be constantly on.