146 lines
3.2 KiB
Plaintext
146 lines
3.2 KiB
Plaintext
|
#include <LiquidCrystal.h>
|
||
|
#include <NewSoftSerial.h>
|
||
|
#include <CAN.h>
|
||
|
#include <pinout.h>
|
||
|
//#include <SoftwareSerial.h>
|
||
|
|
||
|
#define rxPin 4
|
||
|
#define txPin 3
|
||
|
#define XBEE_RTS 8
|
||
|
#define ETH_RTS 19
|
||
|
|
||
|
// Pin definitions for the 74HC165 PISO shift register (reads button column state)
|
||
|
#define INDATAPIN 16
|
||
|
#define INCLOCKPIN 14
|
||
|
#define INLOADPIN 15
|
||
|
|
||
|
#define IDWAITED 200
|
||
|
#define OWNID 100
|
||
|
|
||
|
boolean pressed[8] = {1,1,1,1,1,1,1,1};
|
||
|
boolean button_state[8] = {1,1,1,1,1,1,1,1};
|
||
|
|
||
|
NewSoftSerial mySerial= NewSoftSerial(rxPin, txPin);
|
||
|
|
||
|
// initialize the library with the numbers of the interface pins
|
||
|
LiquidCrystal lcd(7, 6, 5, 18, 17, 9);
|
||
|
|
||
|
long Seconds = 0;
|
||
|
long time = 0;
|
||
|
|
||
|
void setup() {
|
||
|
Serial.begin(57600);
|
||
|
mySerial.begin(9600);
|
||
|
CAN.begin(1);
|
||
|
|
||
|
pinMode(rxPin, INPUT);
|
||
|
pinMode(txPin, OUTPUT);
|
||
|
pinMode(XBEE_RTS, OUTPUT);
|
||
|
pinMode(ETH_RTS, INPUT);
|
||
|
|
||
|
// 165 Setup
|
||
|
pinMode(INDATAPIN, INPUT);
|
||
|
pinMode(INCLOCKPIN, OUTPUT);
|
||
|
pinMode(INLOADPIN, OUTPUT);
|
||
|
|
||
|
digitalWrite(XBEE_RTS,LOW);
|
||
|
|
||
|
// set up the LCD's number of columns and rows:
|
||
|
lcd.begin(16, 2);
|
||
|
// Print a message to the LCD.
|
||
|
lcd.print("hello, world!");
|
||
|
time = millis();
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
// set the cursor to column 0, line 1
|
||
|
// (note: line 1 is the second row, since counting begins with 0):
|
||
|
|
||
|
Seconds=millis()/1000;
|
||
|
checkButtons();
|
||
|
|
||
|
CAN_TxMsg.id = OWNID;
|
||
|
for (int i=0;i<8;i++)
|
||
|
{
|
||
|
CAN_TxMsg.data[i] = button_state[i];
|
||
|
if (button_state[i])
|
||
|
{
|
||
|
lcd.setCursor(i+4, 1);
|
||
|
lcd.print("X");
|
||
|
//mySerial.print(0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
lcd.setCursor(i+4, 1);
|
||
|
lcd.print("O");
|
||
|
//mySerial.print(1);
|
||
|
}
|
||
|
}
|
||
|
CAN_TxMsg.header.length = 8;
|
||
|
CAN.send(&CAN_TxMsg);
|
||
|
delay(10);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/*if (Serial.available())
|
||
|
{
|
||
|
//Seconds=millis()/1000;
|
||
|
Seconds=Serial.read();
|
||
|
}*/
|
||
|
// print the number of seconds since reset:
|
||
|
|
||
|
/*lcd.setCursor(0, 1);
|
||
|
lcd.print(Seconds);*/
|
||
|
|
||
|
//delay(100);
|
||
|
//Serial.println("hello, world!");
|
||
|
|
||
|
/*if ((millis()-time)>=1000)
|
||
|
{
|
||
|
time = millis();
|
||
|
while(digitalRead(ETH_RTS));
|
||
|
Serial.println("Hello, world!");
|
||
|
while(digitalRead(ETH_RTS));
|
||
|
Serial.println(Seconds);
|
||
|
mySerial.println("Hello, world!");
|
||
|
mySerial.println(Seconds);
|
||
|
}*/
|
||
|
}
|
||
|
|
||
|
void checkButtons(){
|
||
|
|
||
|
digitalWrite(INLOADPIN, LOW); // read into register
|
||
|
digitalWrite(INLOADPIN, HIGH); // done reading into register, ready for us to read
|
||
|
|
||
|
for(int r=7; r >= 0; r--){ // read each of the 165's 8 inputs (or its snapshot of it rather)
|
||
|
|
||
|
// tell the 165 to send the first inputs pin state
|
||
|
digitalWrite(INCLOCKPIN, LOW);
|
||
|
|
||
|
button_state[r]=digitalRead(INDATAPIN);
|
||
|
|
||
|
/*if(pressed[r] != digitalRead(INDATAPIN)){ // read the state
|
||
|
pressed[r] = digitalRead(INDATAPIN);
|
||
|
}*/
|
||
|
|
||
|
/*if (digitalRead(INDATAPIN))
|
||
|
{
|
||
|
lcd.setCursor(r+4, 1);
|
||
|
lcd.print("X");
|
||
|
mySerial.print(0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
lcd.setCursor(r+4, 1);
|
||
|
lcd.print("O");
|
||
|
mySerial.print(1);
|
||
|
}*/
|
||
|
|
||
|
// tell the 165 we are done reading the state, the next inclockpin=0 will output the next input value
|
||
|
digitalWrite(INCLOCKPIN, 1);
|
||
|
}
|
||
|
mySerial.println();
|
||
|
|
||
|
}
|