I am working on a project with my MBED microcontroller and I'm running into some snags, because I'm new to it and getting myself confused with how exactly everything works.
I have my MBED hooked up to a 74HC595, which in turn is hooked up to a 7-segment display. I am currently just trying to test the seven segment by creating some sort of counter that goes from 0-9. However, I'm not sure how to do this. Below is my code and how I have it hooked up, I have a few extra declarations in place for the final project, so please just ignore them:
#include "mbed.h"
SPI spi(p11,p12, p13);
DigitalOut red(p25);
DigitalOut green(p26);
DigitalOut cs(p14);
DigitalIn button(p27); //enter
DigitalIn button2(p28); //down
DigitalIn button3(p29); //up
char switchWord;
char record;
int i;
int main() {
spi.format(8,0);
while(1) {
switchWord=0x3F;
if(button==1)
switchWord=switchWord^0x06;
if(button2==1)
switchWord=switchWord^0x5B;
cs=0;
record=spi.write(switchWord);
cs=1;
wait(0.01);
red=0;
green=0;
record=record&0x03;
if(record==1)
red=1;
if(record==2)
green=1;
if(record==3){
red=1;
green=1;
}
}
}
Obviously this isn't working how I want it to, I have tried several different ways to get it to count up, and I have been playing with 2's compliment but it's been awhile since I learned about that so I am really fuzzy on it and I couldn't get it to work. Obviously counting up in this set of binary will be different since the 7-segment displays zero when 6/7 LEDs are set to 1, instead of all zeros, so I can't just add the next number or I get a nonsense display. I eventually want to be able to count from 0-9 by hitting the first button, and count down with the second button, but I can't even figure out how to get it to go from 0-1 so if I can get that I think I can get the ball rolling.
I hope this is all clear and I appreciate any help I can get! Thanks!
Alli