Hey guys,
I’m new to Arduino and would like a little help understanding what PIND is and how to Serial.println (PIND); to see what value it currently is. Currently I’m trying to print the value of PIND in step 7 to verify it’s value. Also why in each test step 1-8 the PIND doubles it’s value?
/ variables
int failCount = 0;
int inp = 0; // generic digital port input var
int testing = 0; // test number or 0 if not testing
int td = 100; // time LED is on during power up test
int td2 = 20; // time LED is on during test so poeple can see them
int i = 0; // generic indexin vars
int x = 0;
int ledGreen = 16; // some port assigments here
int ledRed = 17;
int startButton = 18;
int cableSel = 19;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pins
Serial.begin(9600);
pinMode(startButton, INPUT_PULLUP);
pinMode(cableSel, INPUT_PULLUP);
DDRD = DDRD | B00000000; // set D port as inputs
pinMode(ledGreen, OUTPUT);
pinMode(ledRed, OUTPUT);
for (int i=8; i <= 15; i++){ // set outputs
pinMode(i, OUTPUT);
delay(10);
}
outputsOff();
digitalWrite(ledGreen, HIGH); //LED has common cathode, high = off.
digitalWrite(ledRed, HIGH);
// test lights
for (int i=8; i <= 15; i++){ // cycle through leds at reset
digitalWrite(i, HIGH);
delay(td);
digitalWrite(i, LOW);
delay(td);
}
digitalWrite(ledGreen, LOW); // cycle the red/green led now
delay(500);
digitalWrite(ledGreen, HIGH);
delay(100);
digitalWrite(ledRed, LOW);
delay(500);
digitalWrite(ledRed, HIGH);
delay(500);
}
// the loop routine runs over and over again forever:
void loop() {
while(testing == 0){
inp = digitalRead(startButton); // wait for start button
if (inp == 0){
delay(20); // if start button pressed wait 20 more msec
inp = digitalRead(startButton); // check start button again
if (inp == 0){ //if it's still pressed...
while(inp==0){ // wait for the start button to be released
inp = digitalRead(startButton); // keep checking for release
}
testing = 1;
}
}
}
// ************** START OF TESTS *************
// test 1
if(testing == 1){
digitalWrite(8, HIGH); // set input high
delay(td2); // make the led visible to operator
inp = PIND; // read all inputs
if(inp != 1){ // if all inputs <> 1 (or whatever per test)
failCount = testing; // inc failcount for fail blinks
testing = 99; // go beyond all test numbers to fail
}
else{
digitalWrite(8, LOW);// if pass, then turn off LED
testing++; // inc testing to advance to next test
}
}
// test 2
if(testing == 2){
digitalWrite(9, HIGH);
delay(td2);
inp = PIND;
if(inp != 2){
failCount = testing;
testing = 99;
}
else{
digitalWrite(9, LOW);
testing++;
}
}
// test 3
if(testing == 3){
digitalWrite(10, HIGH);
delay(td2);
inp = PIND;
if(inp != 4){
failCount = testing;
testing = 99;
}
else{
digitalWrite(10, LOW);
testing++;
}
}
// test 4
if(testing == 4){
digitalWrite(11, HIGH);
delay(td2);
inp = PIND;
if(inp != 8){
failCount = testing;
testing = 99;
}
else{
digitalWrite(11, LOW);
testing++;
}
}
// test 5
if(testing == 5){
digitalWrite(12, HIGH);
delay(td2);
inp = PIND;
if(inp != 16){
failCount = testing;
testing = 99;
}
else{
digitalWrite(12, LOW);
testing++;
}
}
// test 6
if(testing == 6){
digitalWrite(13, HIGH);
delay(td2);
inp = PIND;
if(inp != 32){
failCount = testing;
testing = 99;
}
else{
digitalWrite(13, LOW);
testing++;
}
}
// test 7
if(testing == 7){
digitalWrite(14, HIGH);
delay(td2);
inp = PIND;
Serial.println(PIND);
if(inp != 64){
failCount = testing;
testing = 99;
}
else{
digitalWrite(14, LOW);
testing++;
}
}
// test 8
if(testing == 8){
digitalWrite(15, HIGH);
delay(td2);
inp = PIND;
if(inp != 128){
failCount = testing;
testing = 99;
}
else{
digitalWrite(15, LOW);
testing++;
}
}
delay(500); // break up testing lights and status light for aesthetics
if(testing > 0){
if(failCount == 0){
blinkPass();
}
else{
blinkError(failCount);
}
}
testing = 0;
failCount = 0;
delay(1000);
}
/*************************************************************************
**** SUBROUTINES ****
**************************************************************************/
// if all tests pass, flash green led, and wait for button press & release
void blinkPass(){
int d = 0;
do{
inp=digitalRead(startButton);
digitalWrite(ledGreen, LOW);
delay(100);
digitalWrite(ledGreen, HIGH);
delay(100);
inp = digitalRead(startButton);
if (inp == 0){
delay(20);
inp = digitalRead(startButton);
if (inp == 0){
do{
inp = digitalRead(startButton);
}
while(inp==0);
d = 1;
}
}
}
while(d == 0);
}
// if fail, flash the failing test number with the red led and wailt for button press
void blinkError(int bnum){
//bnum = 5;
int d = 0;
do{
inp=digitalRead(startButton);
for (int i=1; i <= bnum; i++){
digitalWrite(ledRed, LOW);
delay(300);
digitalWrite(ledRed, HIGH);
delay(300);
inp = digitalRead(startButton);
if(inp == LOW){
d = 1;
break;
}
}
for (int z = 0; z <= 10; z++){
inp = digitalRead(startButton);
if(inp == LOW){
d = 1;
outputsOff();
break;
}
delay(200);
}
}
while(d == 0);
digitalWrite(ledRed, HIGH);
}
void outputsOff() {
for (int i=7; i <= 15; i++){ // turn outputs off
digitalWrite(i, LOW);
delay(10);
}
}