Instructions

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.

To program in non-Arduino C with our own main function:

  1. Start a new sketch.
  2. Delete (or comment out) all content in the .ino file.
  3. Above your code, you should see the name of the .ino file on the left side. Go to the right side and you should see three dots. Click those dots and select “New Tab”.
  4. You name the new tab “main.c”.
  5. Now you can write your own main function and any other code needed for your solution in “main.c”.

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):

  • digitalRead
  • digitalWrite
  • analogRead
  • analogWrite
  • attachinterrupt
  • pinMode

Deliverable A

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.

Deliverable B

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.

Deliverable C

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.

Deliverable D

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.

Turn in to Blackboard

A zip file with all code. This could be one sketch that solves Deliverable D or a sketch for each. (30 points)

Demo Rubric

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