The Arduino comes with excellent software libraries and build processes that make our lives easier. Not all microprocessors have this. This assignment will ask you to program your Arduino WITHOUT the helpful libraries, but we have to trick the IDE a little to get to that point.
NOTE: You will likely need to include the following header files in your code:
#include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h>
The following deliverables should be performed without using any Arduino-specific functions. Instead, use the AVR functions and registers as discussed in class. You will need the documentation for your AVR processor to complete this assignment. The ATMega2560 used in the Arduino Mega is here: https://www.microchip.com/en-us/product/atmega2560. If you have another version, you will need to make sure you find the correct datasheet.
Do not include “Arduino.h” in your file. Do not use these functions (not a complete list):
Write code to blink an external LED (not the onboard LED) at 2 Hz. You will want to connect the LED to a PWM-capable pin.
Now setup the LED to use PWM. Cycle through five levels of brightness (0%, 25%, 50%, 75%, 100%) on the LED, pausing for 500 milliseconds at each level.
Connect a potentiometer to an Analog pin on the Arduino. Write code that uses the potentiometer input to the Arduino to control the LED’s brightness from 0% to 100%. Note: this most be done in software, you cannot connect the LED directly to the potentiometer.
Connect a button to the Arduino. Set up an interrupt that will swap between B and C above when the button is pressed. For example, if the system starts with the LED sequence displayed, pressing the button should switch the LED to be controlled by the potentiometer. Pressing the button again should switch back to the sequence. When switching to the sequence, it can either start where it left off or start again, your choice. For full credit, the output should be able to be swapped at any time.
If you complete all deliverables, you only need to demonstrate D.
A zip file with all code. This could be one sketch that solves Deliverable D or a sketch for each. (30 points)
5 points – LED output
5 points – LED with brightness changes
5 points – Potentiometer input
5 points – Button interrupt
5 points – Output controlled by button
5 points – Output able to be changed at any time