So I am completely green at the programming. A lot of experience with hardware and electronics theory. I bought a UNO and a shield as a kit with a 4 digit 7 segment display. Took me not much more than an hour to get everything assembled, upload the counter program, and have a working 4 digit counter.
Next I wanted to change the program so i could put a digit on a line of the program and just have it show that one digit, after three days of reading and tweaking, playing etc. I got it. Next step I want to enter the base10 digit into the serial monitor and have it displayed on the 7 segment LED display. It did not take me too much to get this working but I find one part strange.
During the Serial Troubleshooting phase I had the UNO print back to the monitor what it received. When I send a 0 it sends back a 48. I send 2 it sends 50, and so on. I just added a line to subtract 48 and both the serialprint and my LED display reads the same number. Its working, but why is this.
I have set the baud rate in the serial monitor same as in the code, 4800. I chose 4800 because I hope to eventually connect to NMEA0183.
//1 Digit Arduino Counter
#define A A4
#define B 13
#define C 10
#define D 9
#define E 8
#define F A1
#define G 11
// Pins driving common anodes
#define CA1 12
// Pins for A B C D E F G, in sequence
const int segs[7] = {A4, 13, 10, 9, 8, A1, 11};
// Segments that make each number
const byte numbers[10] = { 0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010, 0b0000010, 0b1111000, 0b0000000, 0b0010000};
int dataIN = 0;
void setup() {
pinMode(A4, OUTPUT);
pinMode(13, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
Serial.begin(4800);
}
void loop()
{
if (Serial.available() > 0){
dataIN = Serial.read();
dataIN = dataIN - 48;
Serial.print("I received: ");
Serial.println(dataIN);
}
//calls the data out of the array
lightDigit1(numbers[dataIN]);
}
//activate current digita anode
void lightDigit1(byte number) {
digitalWrite(CA1, HIGH);
lightSegments(number);
}
//activate LED segments
void lightSegments(byte number) {
for (int i = 0; i < 7; i++) {
int bit = bitRead(number, i);
digitalWrite(segs[i], bit);
}
}
My next step is to get three digits working and maybe a negative sign in the same fashion
Thanks everyone for the support, Brian