What I mean by this title/subject is for the LED on my Mega 2560 board to turn on when it encounters a 1 in the code and turns off when it encounters a 0 in the code. Is this possible?
if (someVariable == 1)
{
digitalWrite(someLed, HIGH);
}
if (someVariable == 0)
{
digitalWrite(someLed, LOW);
}
Or the shortform version:
digitalWrite(someLed,someVariable?HIGH:LOW);
To test on a specific bit use the & (and) operator:
digitalWrite(someLed,someVariable&0x01?HIGH:LOW);
digitalWrite(someOtherLed,someVariable&0x02?HIGH:LOW);
etc.
To use the build-in led you can use the reference LED_BUILTIN
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
ro_har_:
What I mean by this title/subject is for the LED on my Mega 2560 board to turn on when it encounters a 1 in the code and turns off when it encounters a 0 in the code.
To precisely what "code" do you refer here?
Or the shortform version:
digitalWrite(someLed,someVariable?HIGH:LOW);
My guess is that the OP is not ready for the ternary operator and as has been pointed out we don’t know exactly what he/she wants to do anyway
UKHeliBob:
My guess is that the OP is not ready for the ternary operator and as has been pointed out we don’t know exactly what he/she wants to do anyway
I am quite new to Arduino and raspberry pi style of coding, I did a bit in my college course a couple of years ago but now wanting to learn more as I have a job interview for software developer coming this next week.
now wanting to learn more as I have a job interview for software developer coming this next week.
You may have left it a little late
Can you please explain what you mean by
when it encounters a 1
What I mean is that someone will put in 10 1s and 0s, then you would click run and when it notices a 1 the light flashes, or something along those lines.
I assume that the user will input the 10 1s and 0s using the Serial monitor
What have you tried so far ?
ro_har_:
now wanting to learn more as I have a job interview for software developer coming this next week.
I've never earned a dime writing C++ code but here goes:
Your interviewer asks you to write a simple program to demonstrate your skills, something like -
ro_har_:
... someone will put in 10 1s and 0s, then you would click run and when it notices a 1 the light flashes, or something along those lines.
How would you write this? Pseudo code acceptable.
turn on when it encounters a 1 in the code and turns off when it encounters a 0
You can do this using a bitmask.
as I have a job interview for software developer coming this next week.
Umm....Good Luck.
dougp:
Your interviewer asks you to write a simple program to demonstrate your skills, something like -
The problem is I have not done any software developing since college and that was only computer based, we did not use raspberry pi's, luckily this interview is for a level 1 training position, so I just have to show a willing to learn software development. Along with a written test.
Even if you can't program I would expect you to be able to draw a flowchart showing the steps required or an explanation of how the program would work
What would come first ?
What next ?
What tests are needed ?
What do you do with the results of the tests ?
How would you read the next input ?
How do you know that you have read all of the input ?
UKHeliBob:
Draw a flowchart showing the steps required
Yeah that sounds quite a good idea as I do still know a bit about flow charts (would need to research them a little).
Don't over think it
Pencil and paper
Boxes for actions
Diamonds for tests
Flow charts!
Oh my!
Don't mock. They are very useful in visualising the paths through a program and making sure that there are no loose ends (literally) Just because they are old school does not make them any less useful. How would you approach the task ?
Paul__B:
Flow charts!Oh my!
![]()
Ah, you prefer Nassi-Shneidermann diagrams
Sounds like the OP has a dev career in the bag.