Hey gang,
I'm stumped over this, and I've managed to stump Coding Badly so far too.
I have what started as a simple test code to read some buttons, & make onboard LED flash to confirm wiring, then writing all 0s & all 1s to a TPIC6B595 shift register to test turning LED strings on & off.
The button read/LED on/off worked fine.
Added in the SPI.transfers()s - and nothing happened.
Commented out the SPI.transfers - LED followed the button press again.
CodingBadly took a look and pointed out I had not used SPI.begin (Big head slap!).
Added that, still no LED.
Added serial.begin and put in some prints to make sure the code was actually executing in loop, and it does.
Feeling aggravated now, I backed up to 1.0.1, 1.0, renamed the file & went back to -0023. Still no go.
Deleted 1.0.2, reinstalled it.
Still no go! What is going on?
Windows 7, Duemilanove bootloaded as an Uno from 1.0.2 via MKii, brand new '328P.
Testing is just a jumper wire from D5 to GND, watching the LED and the serial monitor. Nothing else is connected.
#include <SPI.h>
byte latch = 10;
byte ledPin = 13;
void setup(){
Serial.begin(9600);
SPI.begin();
pinMode (2, INPUT);
digitalWrite(2, HIGH);
pinMode (3, INPUT);
digitalWrite(3, HIGH);
pinMode (4, INPUT);
digitalWrite(4, HIGH);
pinMode (5, INPUT);
digitalWrite(5, HIGH);
pinMode (ledPin, OUTPUT);
pinMode (9, OUTPUT);
digitalWrite(9, LOW); // OE*
pinMode (latch, OUTPUT);
digitalWrite (ledPin, HIGH);
}
void loop(){
if (digitalRead(5) == LOW){
digitalWrite(latch, LOW);
Serial.println("input low - latch low");
SPI.transfer(0xFF);
digitalWrite (latch, HIGH);
Serial.println("input low - latch high");
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(latch, LOW);
Serial.println("input high - latch low");
SPI.transfer(0x00);
digitalWrite (latch, HIGH);
Serial.println("input high - latch high");
digitalWrite (ledPin,LOW);
}
}
Errors/warnings I see in compile with verbose output after the first compile when the IDE is started:
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\HardwareSerial.cpp: In function 'void store_char(unsigned char, ring_buffer*)':
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\HardwareSerial.cpp:83: warning: comparison between signed and unsigned integer expressions
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\HardwareSerial.cpp: In function 'void __vector_18()':
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\HardwareSerial.cpp:117: warning: unused variable 'c'
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\HardwareSerial.cpp: In member function 'void HardwareSerial::begin(long unsigned int, byte)':
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\HardwareSerial.cpp:364: warning: unused variable 'current_config'
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\HardwareSerial.cpp: In member function 'virtual size_t HardwareSerial::write(uint8_t)':
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\HardwareSerial.cpp:463: warning: comparison between signed and unsigned integer expressions
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\Print.cpp: In member function 'size_t Print::print(const __FlashStringHelper*)':
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\Print.cpp:44: warning: '__progmem__' attribute ignored
C:\Arduino-1.0.2\hardware\arduino\cores\arduino\Tone.cpp:119: warning: only initialized variables can be placed into program memory area
When I compile a 2nd time I don't see these. But digitalWrite is still not working,