I'm a bit stumped on this one, I can see a couple of ways of maybe getting this to work but they both seem rather longwinded and I'm sure there are simpler ways. Basically I have the following;
/*Cable Tester
LCD circuit - Arduino (WH2004A):
* LCD RS pin to digital pin 12 (4)
* LCD Enable pin to digital pin 11 (6)
* LCD D4 pin to digital pin 5 (11)
* LCD D5 pin to digital pin 4 (12)
* LCD D6 pin to digital pin 3 (13)
* LCD D7 pin to digital pin 2 (14)
* LCD R/W pin to ground
10K variable resistor:
* ends to +5V and ground
* wiper to LCD VO pin 3
Sense
* ground via 4k7
* pull up to +3V3 or +5V to close circuit
LED
* pin 13 > LED > res > gnd
74HC164N - Arduino
* data - pin 6
* clock - pin 7
* powered from 3V3
*/
// include the library code:
#include <LiquidCrystal.h>
// pin constants setup
const int dataPin = 6;
const int clockPin = 7;
const int sensePin = 8;
const int outputPin = 13;
// variable for the input-sensePin status
int loomConnection = 0;
// initialise the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(clockPin, OUTPUT); // make the clock pin an output
pinMode(dataPin, OUTPUT); // make the data pin an output
pinMode(sensePin, INPUT); //make sense pin an input
pinMode(outputPin, OUTPUT); //set pin 13 as output (LED on board for testing)
// shiftOut(dataPin, clockPin, LSBFIRST, B00000000); // send this binary value to the shift register
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// startup screen
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Control Loom Test");
lcd.setCursor(0, 1);
lcd.print("Test Code");
lcd.setCursor(0, 2);
lcd.print("Written By");
lcd.setCursor(0, 3);
lcd.print("Stuart Whitchurch");
delay(1000); //delay is how long startup screen is displayed
// output screen
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Gender : ");
lcd.setCursor(0, 1);
lcd.print("Row : ");
lcd.setCursor(0, 2);
lcd.print("Pin No. : ");
lcd.setCursor(0, 3);
lcd.print("Sense Pin:");
//This screen stays put during the following loop
}
void loop() {
//count to 56 turning on outputs as we go
for (int j = 0; j < 56; j++) {
shiftOut(dataPin, clockPin, MSBFIRST, j);
delay(50);
// read the state of the test loop value
loomConnection = digitalRead(sensePin);
// check if the test loop is closed
// if it is, the loomConnection is HIGH
if (loomConnection == HIGH) {
// turn LED on
digitalWrite(outputPin, HIGH);
//set LCD to display loop status
lcd.setCursor(11, 4); //position cursor at the end of the status row
lcd.print("Closed"); //print status
}
else {
// turn LED off
digitalWrite(outputPin, LOW);
//set LCD to display loop status
lcd.setCursor(11, 4); //position cursor at the end of the status row
lcd.print("Open "); //print status (the trailing spaces overwrite the 'ed')
}
}
}
This seems to work fine, it cycles the outputs as far as I can tell but what I want it to do now is pause and display some details on the LCD display when the sense pin is triggered by an output from the shift registers. As I mentioned I can do it with some extensive writing of for\else loop cases for every output but I wondered if there was a better way of telling the counter to stop and hold on the triggered output and then write something to the display?
Hopefully this is as clear as it sounds!