NICTA ed1‎ > ‎

NICTA ed1 Demo

//Dr Pusey's NICTA Board Demo Program

//This code is deliberately not commented - it's your job to figure out how it works!

//To upload this code to the NICTA Board, make sure you select the correct Comm Port

//Change the board type to "Duemilanove or Diecimila"

// it's important to include this library so we can use the LCD display
#include <LiquidCrystal.h>

// set initial parameters and declare variables
LiquidCrystal lcd(6, 8, 2, 3, 4, 5);
byte data = 0;
int i=1;
int lightsense = 0;
int tempsense = 0;
int lbutton=1;
int rbutton=1;
int delayTime = 50;
double potValue;
char lightString[5];
char potString[5];
char tempString[5];


void setup() {
 
  pinMode(12, OUTPUT); //SR Data
  pinMode(10, OUTPUT); //SR Clock 
  pinMode(11, OUTPUT); //SR Latch
     
  // set up NICTA BOARD PINS
 
  pinMode(7, OUTPUT);    //LCD RW
  pinMode(9, OUTPUT);    //PIEZO BUZZER
  pinMode(13, OUTPUT);    //LED
 
  pinMode(14, INPUT);    //Left Button
  digitalWrite(14, HIGH);
  pinMode(15, INPUT);    //Right Button
  digitalWrite(15, HIGH);
 
  tone(9, 2000, 300);
  delay(200);
  tone(9, 3000, 200);
  delay(200);
  tone(9, 4000, 300);
 
  lcd.begin(16, 2);
  lcd.print("Hello STEM CLUB!");
}

void loop() {
  //This loop changes the location of the LED marker (moving Light) from left to right and back again.
  //During each itteration, the function "processDisplay" is activated.
  //processDisplay is where all of the other stuff happens.
 
  int index;                         

  lcd.setCursor(0, 1);
  lcd.print(millis() / 1000);
  for(index = 0; index <= 7; index++)
  {
    shiftWrite(index, HIGH);    // turn LED on
    delay(delayTime);           // pause to slow down the sequence
    shiftWrite(index, LOW);     // turn LED off
    processDisplay();
  }
  for(index = 6; index >= 1; index--)
  {
    shiftWrite(index, HIGH);    // turn LED on
    delay(delayTime);           // pause to slow down the sequence
    shiftWrite(index, LOW);     // turn LED off
    processDisplay();
  }
}

void processDisplay()
{
  lbutton = digitalRead(14);
  rbutton = digitalRead(15);
  potValue = analogRead(3);
  lcd.setCursor(0, 1);
  lcd.print(millis() / 1000);
  lightsense = analogRead(7);
  tempsense = (0.25 * analogRead(6) - 20.50);
  sprintf(tempString,"%02d%cC", tempsense,223);
  lcd.setCursor(5, 1);
  lcd.print(tempString);
  lcd.setCursor(11, 1);
  lcd.print(5-potValue*0.004883);
  lcd.setCursor(15, 1);
  lcd.print("V");
  digitalWrite(13, lbutton);
  if (lbutton==0)
    {
      tone(9, lightsense*50, 100);
    }
  if (rbutton==0)
    {
      tone(9, 10000-potValue*10, 100);
    }
}

//This bit of code writes the current state of the LEDs to the board
void shiftWrite(int desiredPin, boolean desiredState)
{
  bitWrite(data,desiredPin,desiredState);
  shiftOut(12, 10, MSBFIRST, data);
  digitalWrite(11, HIGH);
  digitalWrite(11, LOW);
}