954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Urgent c++ help needed!!

Hi all,

Currently trying to write a piece of code for a project at university, with very little C Compiler experience I am struggling...

Basically- we have 8 LED's, and 8 switches. We want 4 of the 8 LED's to light up at random when the program is run, that then have to be switched off in order using the corresponding switches. They must only be able to be done in order!

E.g If LED's 0,2,4,7 light up, switch 0 must be turned off in order for LED 0 to go off, and LED 2 can only be switched off if LED 0 is already turned off... etc etc.

Once all 4 are turned off in order, we need a small time delay (e.g 3 second) before the LEDs are randomized again and 4 more come on. These will need to be turned off as before... but in REVERSE order (e.g 6,5,3,1).

Any help will be much appreciated!

Cheers

mmpjb

mmpjb
Newbie Poster
3 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

What microcontroller?

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 
What microcontroller?


If you're referring to what I think you are... its a PIC18F45h

If thats completely wrong... I apologise.

mmpjb
Newbie Poster
3 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

1. So does it have enough IO to have 8 leds and 8 switches? If not: How do yo think you should solve that?
2. you need to program a function that picks a random number between 0-8
3. You need to make a timer
4. For each button pressed, you need to check if all leds on the left of this one are dimmed.

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 
1. So does it have enough IO to have 8 leds and 8 switches? If not: How do yo think you should solve that? 2. you need to program a function that picks a random number between 0-8 3. You need to make a timer 4. For each button pressed, you need to check if all leds on the left of this one are dimmed.

1.Yes, it does have enough IO to have 8leds and 8 switches
2. indeed i do- thanks for the link- i'll take a look
3. i think i know how to make a timer so thats ok
4. not entirely sure what you mean by this point!

many thanks for your continued help :)

mmpjb

mmpjb
Newbie Poster
3 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

not urgent

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: