All Files Functions Variables Macros
Macros | Functions | Variables
LightUp.h File Reference

Detailed Description

Main library file of the Lightup project.

Lightup.h is the main library file of the Lightup project

#include "Arduino.h"
#include "pin.h"
#include "pitches.h"
#include "internalTemp.h"

Go to the source code of this file.

Macros

#define INPUT_1   A0
 These pins connect to block terminals designed for digital and analog input. More...
 
#define INPUT_2   A1
 
#define INPUT_3   A2
 
#define INPUT_4   A3
 
#define INPUT_5   A4
 
#define INPUT_6   A5
 
#define OUTPUT_A   5
 
#define OUTPUT_B   10
 
#define OUTPUT_C   9
 
#define OUTPUT_D   11
 
#define OUTPUT_E   13
 
#define OUTPUT_F   6
 
#define _LU_INPUT_SIGNAL_1   7
 
#define _LU_INPUT_SIGNAL_2   2
 
#define _LU_INPUT_SIGNAL_3   1
 
#define _LU_INPUT_SIGNAL_4   3
 
#define _LU_INPUT_SIGNAL_5   12
 
#define _LU_INPUT_SIGNAL_6   4
 
#define setup()   user_setup()
 Rename the user program's setup function to user_setup. More...
 
#define analogRead(pin)   lightup_analogRead(pin)
 Rename Arduino core functions that need to be intercepted. More...
 
#define digitalRead(pin)   lightup_digitalRead(pin)
 

Functions

void lightup_setup_io ()
 Configure the input and output pins on the block. More...
 
void lightup_setup_timer ()
 
void user_setup ()
 
int lightup_analogRead (uint8_t pin)
 
int lightup_digitalRead (uint8_t pin)
 
static void setSignalLED (uint8_t signalPin, uint8_t inputPin, boolean isAnalog)
 Helper functions. More...
 
void enableInputLights ()
 Global functions. More...
 
void disableInputLights ()
 
 ISR (TIMER1_COMPA_vect)
 This code runs every millisecond. More...
 

Variables

static boolean input1IsAnalog = false
 Store which input pins have been read as analog pins. More...
 
static boolean input2IsAnalog = false
 
static boolean input3IsAnalog = false
 
static boolean input4IsAnalog = false
 
static boolean input5IsAnalog = false
 
static boolean input6IsAnalog = false
 
static boolean inputLightsAreEnabled = true
 Globally enable or disable input signal lights. More...
 

Macro Definition Documentation

#define _LU_INPUT_SIGNAL_1   7

These pins connect to signal LEDs next to the corresponding input pins. Reading the signal on the input pin and then writing it to the signal LED guarantees that the value on the signal LED accurately reflects what the software sees. This is important in the case of internal pull up resistors being enabled and floating connections. This technique also requires no circuitry on the input pins themselves preserving the integrity of analog signal values.

#define _LU_INPUT_SIGNAL_2   2
#define _LU_INPUT_SIGNAL_3   1
#define _LU_INPUT_SIGNAL_4   3
#define _LU_INPUT_SIGNAL_5   12
#define _LU_INPUT_SIGNAL_6   4
#define analogRead (   pin)    lightup_analogRead(pin)

Rename Arduino core functions that need to be intercepted.

#define digitalRead (   pin)    lightup_digitalRead(pin)
#define INPUT_1   A0

These pins connect to block terminals designed for digital and analog input.

We're using the Arduino Leonardo's bootloader and configuration so the pin numbers are defined based on the Leonardo, not the underlying Atmel 32u4.

#define INPUT_2   A1
#define INPUT_3   A2
#define INPUT_4   A3
#define INPUT_5   A4
#define INPUT_6   A5
#define OUTPUT_A   5

These pins connect to block terminals designed for digital and analog (PWM) output. The block's output terminals are connected to LEDs to display the digital signal value.

#define OUTPUT_B   10
#define OUTPUT_C   9
#define OUTPUT_D   11
#define OUTPUT_E   13
#define OUTPUT_F   6
void setup ( )    user_setup()

Rename the user program's setup function to user_setup.

Arduino setup actually invokes the lightup setup routine. The end of this routine calls user_setup which invokes the program's setup routine.

Run the user's setup code. This is normally in the function called "setup" in Arduino code.

Function Documentation

void disableInputLights ( )
void enableInputLights ( )

Global functions.

Functions to disable features of the core.

ISR ( TIMER1_COMPA_vect  )

This code runs every millisecond.

int lightup_analogRead ( uint8_t  pin)

These functions intercept calls to the Arduino core libraries. These disable pullups when a pin is used in analog mode and also disable the signal indicator LEDs.

This intercepts what would otherwise be a call to analogRead. In addition to calling analogRead, it stores the call so we know the pin is analog.

int lightup_digitalRead ( uint8_t  pin)

This intercepts what would otherwise be a call to digitalRead. In addition to calling wiring_digitalRead, it stores the call so we know the pin is digital.

void lightup_setup_io ( )

Configure the input and output pins on the block.

These functions are called during initialization to setup the I/O ports and debugging lights on the block.

void lightup_setup_timer ( )

Disable interrupts while we configure interrupts.

Set Timer1 to interrupt at 1kHz (every millisecond).

Set compare match register for 1kHz increments OCR1A = CLOCK_FREQUENCY / PRESCALER / INTERRUPT_FREQUENCY - 1

= (8*10^6) / 1 / (1*10e3) - 1

Select no prescaler and enable counter

Turn on CTC mode

Enable timer compare interrupt so that ISR runs every millisecond.

Enable interrupts.

static void setSignalLED ( uint8_t  signalPin,
uint8_t  inputPin,
boolean  isAnalog 
)
static

Helper functions.

Helper function that only sets signal LEDs when pin is digital.

void user_setup ( )

This function contains the user's program setup code. This is normally in a function called "setup" for Arduino, but we overwrite that function with the LightUp's setup routine. To prevent users from getting confused, a macro renames their setup to user_setup automatically.

Variable Documentation

boolean input1IsAnalog = false
static

Store which input pins have been read as analog pins.

boolean input2IsAnalog = false
static
boolean input3IsAnalog = false
static
boolean input4IsAnalog = false
static
boolean input5IsAnalog = false
static
boolean input6IsAnalog = false
static
boolean inputLightsAreEnabled = true
static

Globally enable or disable input signal lights.