taliafpf code 1

#include <RGB_GLCD.h>

//Three time keepers
  long time = 0;
  long count = 0;
  int data = 0;
 
 // Declare an instance of the class
GLCD myGLCD;
 


void setup() {
  //pins we used.
  pinMode(13, OUTPUT); //LED Light temp
  pinMode(12, OUTPUT); //LED Light temp
 
  pinMode(6, OUTPUT); //green LED Light
  pinMode(5, INPUT);  //voltage sensor
  pinMode(3, INPUT);  //Data in
  pinMode(2, OUTPUT);  //CS
  pinMode(4, OUTPUT); //I/O clock
 
  //For LCD SCreen
  randomSeed(analogRead(0));
  myGLCD.initLCD();
}

//Main loop
void loop(){
  myGLCD.clrScr();
  myGLCD.setContrast(64);
  TimeKeeper();
  CS();
  if(count%4 == 0)
  {
    dataRead();
  }
  delay(10);

}

/*This part of the kode makes a 25 Hz clock.
We used mod functions to make our clocks because it
takes the least amount of code*/

void TimeKeeper(){
  if(time != millis())  // Incraments count if micros() changes
  {
    count = count + 1;
    time = millis();
  }
  if(count == 50000)  // 1 Second Interval
  {
    count = 0;
  }
 
  if(count%4 == 0 ||count%4 == 1)  // even = low
  {
    digitalWrite(4, LOW);
  }
  else if(count%4 == 2 || count%4 == 3)
  {
    digitalWrite(4, HIGH);   // odd = high
  }
}


/*This is the Chip select which has
to be up for 8 clock cycles to read the data.*/

void CS(){
 if(count%64 <= 29)  // even = low
  {
    digitalWrite(2, LOW);
  }
  else
  {
    digitalWrite(2, HIGH);   // odd = high
  }
}


/*  This reads our data and coverts
it form binary to decimal. */

void dataRead()
{
 
 
  if(count%64 == 0)
  {
    data = 0;
  }
  if(count%64==0)
  {
    if (digitalRead(3) == HIGH)
    {
      data = data + 128;
    }
  }
  else if(count%64==4)
  {
    if (digitalRead(3) == HIGH)
    {
      data = data + 64;
    }
  }
  else if(count%64==8)
  {
    if (digitalRead(3) == HIGH)
    {
      data = data + 32;
    }
  }
  else if(count%64==12)
  {
    if (digitalRead(3) == HIGH)
    {
      data = data + 16;
    }
  }
  else if(count%64==16)
  {
    if (digitalRead(3) == HIGH)
    {
      data = data + 8;
    }
  }
  else if(count%64==20)
  {
    if (digitalRead(3) == HIGH)
    {
      data = data + 4;
    }
  }
  else if(count%64==24)
  {
    if (digitalRead(3) == HIGH)
    {
      data = data + 2;
    }
  }
  else if(count%64==28)
  {
    if (digitalRead(3) == HIGH)
    {
      data = data + 1;
    }
  }
  if(count%64 == 56)
  {
    lightUp();
    data = 0;

    
  }
    
}

void lightUp(){
  if(digitalRead(5) == HIGH){
    if(data > 170){
      myGLCD.print('Heineken', 63, 63, 50, 50, 50);
    }
    else{
      myGLCD.print('Budweiser', 63, 63, 50, 50, 50);
    }
  }
  else{
      myGLCD.print('Waiting', 63, 63, 50, 50, 50);
    }
}