Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 7 months ago.
Issues with BusOut
I have 6 LED's, 3 red and 3 green. My green LED's are Active-high, and the red are active-low. In my program I am just trying to simply turn each of them into various combinations of on/off. My green LED's are having no problem, but my red LED's are doing the opposite of what I am trying to code. I know this is because of the set up on my breadboard, but what I'm trying to figure out is how do I switch the initial state of the red LED's.
BusOut blue(LED1,LED2,LED3); BusOut red(p21,p22,p23); BusOut green(p18,p19,p20);
int main() {
while(1) { blue = 0x0; red = 0x7; green = 0x0;
} }
This is how I've had to set it up so they are all off, but as you can see my red is just written differently than my other BusOuts. So what I'm asking is what can I use so that I can have all of my LEDs set to the same code and have the same result? Or is there no other way than to reverse the code?
1 Answer
7 years, 7 months ago.
In the end, because of how the red LEDs are wired, you have to invert the levels that are written to the bus pins. You can simply hide that hardware detail in a function or a macro if you dont want to clutter your code. Something like this should work:
BusOut blue(LED1,LED2,LED3); BusOut red(p21,p22,p23); BusOut green(p18,p19,p20); setBlue(int value) { blue = value; } setRed(int value) { red = ! value; //invert the bits } setGreen(int value) { green = value; } int main() { while(1) { setBlue(0x0); setRed(0x0); setGreen(0x0); } //dont really need to repeatedly set the bits in a while, once will do }