summaryrefslogtreecommitdiff
path: root/trunk/users/bruce/Lcd test/lcd files/New Text Document.txt
blob: b630fe46de22928acfc00b180b4529007480e101 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93



// SIZER        "0123456789012345678901234567890123456789"
char mess[16] = "I2C LCD ";  // Hello style it's working message
char mess1[16] ="Button: ";  // Part of the "a button is being pressed" message
char NUMB[4] =  "000";


//*******************************************************************************************************************
//								                                        MAIN LOOP
//*******************************************************************************************************************

void loop()
{
  for (i=0;i<8;i++)
  {
    LCDwr(mess[i]);                                    // Print-out Hello style message to display one letter at a time
  }
  dispnumb(count);                                     // Print-out counter value to display
  count = count +1;



  
  I2C_RX(MCP23017,GPIOB);                                              // Check if Option buttons 1 to 5 are pressed
  if (int(button)>0)
  {
    for (i=0;i<8;i++)
    {
      LCDwr(mess1[i]);                                                 // Print out button pressed message with number
    }

    dispnumb(int(button)); 
  }
  
  
  delay(2000);                                                         // Delay and do it again
  LCDcmd(ClrLCD);
  delay(200);

  checkbutton();


}


//*******************************************************************************************************************
//								                   SEND DECIMAL NUMBER TO DISPLAY
//*******************************************************************************************************************
void dispnumb(int numbvar)
{
  //int THUS= abs(numbvar/1000);
  int HUNDS= abs(numbvar/100);
  int TENS = abs((numbvar - (HUNDS*100))/10);
  int ONES = abs(numbvar-(HUNDS*100)-(TENS*10));

  NUMB[0] =  HUNDS+48;                                                        // +48 for ASCII conversion
  NUMB[1] =  TENS+48;
  NUMB[2] =  ONES+48;

  for(i=0;i<3;i++)
  {
    LCDwr(NUMB[i]);                                                           // Print-Out 3 digit number at cursor
  }
}

//*******************************************************************************************************************
//								                 READ IF BUTTONS ARE BEING PRESSED
//*******************************************************************************************************************
void checkbutton()                            // Use serial monitor at 9600bps to see buttons that are pressed
{
  I2C_RX(MCP23017,GPIOB);
  buttonPress = int(button);
  switch (buttonPress)                        
  {
  case 1:
    Serial.println("Button-One");
    break;
  case 2:
    Serial.println("Button-Two");
    break;
  case 4:
    Serial.println("Button-Three");
    break;
  case 8:
    Serial.println("Button-Four");
    break;
  case 16:
    Serial.println("Button-Five");
    break; 
  }
}