Check yourself
Try to answer each question before you open its answer.
About the code
What numbers does
analogWritetake?Show the answer
0 to 255. 0 keeps the pin always off, and 255 keeps it always on. 1
How does PWM make an LED look dimmer?
Show the answer
It switches the pin on and off, over and over, very fast. The less of the time the pin is on, the dimmer the LED looks. 9
Why does the sketch divide the reading by 4?
Show the answer
analogReadgives 0 to 1023, butanalogWritetakes 0 to 255. Arduino’s ownanalogWriteexample does the same division. 1
About the registers
These are about step 4. If you skipped it, you can skip them too.
How fast does pin 9 switch on and off?
What does pin 9 do when OCR1A is 0 in this mode?
Show the answer
It stays LOW the whole time. In this mode, OCR1A at 0 (the bottom of the count) keeps the output low all the time. 2
Next is Lesson 4. You’ll read a push button, and see the bit it sets.
All sources for Lesson 3
- Arduino reference: analogWrite
- Microchip ATmega328P datasheet DS40002061A: Timer1 PWM frequency (p135), extreme values (p136), Tables 16-3 and 16-4 (p141); ADC result (p256)
- ArduinoCore-avr, cores/arduino/wiring.c: Timer1 prescaler 64, 8-bit phase-correct PWM
- ArduinoCore-avr, variants/standard/pins_arduino.h: pin 9 is TIMER1A
- Arduino UNO R3 technical specifications: Clock speed: ATmega328P 16 MHz; DC Current per I/O Pin: 20 mA
- Arduino reference: analogRead: values 0 to 1023 on the UNO R3
- Arduino reference: pinMode
- Arduino reference: int
- Arduino: Basics of PWM (Pulse Width Modulation)
- Arduino tutorial: Analog In, Out Serial: knob on A0; LED and 220 ohm resistor in series on pin 9
- Arduino reference: setup()
- Arduino reference: loop()
- Arduino reference: / (division)