School Assignment

I got an assignment. But we can’t figure out how to do it. So the teacher asked us to ask some other people if they would know the answer.

-Use a board with a green LED, a red LED and a button on it.

  • When the button is pressed, the red LED turns on and the green LED turns off. (both lights are off at the beginning)
  • If you then press the button again, the red LED goes out and the green LED goes on.
  • After every 10x presses the text appears: "10 steps, well done".

Lets start with small steps.

What Arduino are you using?

Have you got a resistor for each LED to limit the current?

Can you write a short program to turn the red LED on when the button is pressed?

Can you write a separate program to turn the green LED off when the button is pressed? The two program will be very similar.

...R

Doesn't sound to hard. But what have you tried?

If the answer is nothing, I think it's a bit weird you're asking around here... But let me give you a starting point.

  1. Draw the schematic. (Paper and a pen(cil) usually is easier then Fritzing breadboard messed).
  2. Work ut how to detect a button press. The State change example is a very god start
  3. Actually, I think you're done by then :wink:

MatieKipsate:
-Use a board with a green LED, a red LED and a button on it.
[...]

  • After every 10x presses the text appears: "10 steps, well done".

So where should that text appear? Thin air? :wink: Devil IS in the details.

here maybe this can help you get started

const int LED_RED = 7; //RED LED ON PIN 7
const int LED_GREEN = 8; // GREEN LED ON PIN 8
const int BUTTON = 9; //PUSH BUTTON ON PIN 9 PULL-UP
int BUTTON_COUNTER =0;
unsigned long DEBOUNCE = 0;


void setup() {
  Serial.begin(9600);
  pinMode(BUTTON, INPUT_PULLUP); //DEFINE BUTTON AS INPUT
  pinMode(LED_GREEN, OUTPUT); //DEFINE LEDS PINS AS OUTPUTS
  pinMode(LED_RED, OUTPUT);
  digitalWrite(LED_GREEN, HIGH); //PULL PIN HIGH TO ASSURE OFF
    digitalWrite(LED_RED, HIGH);  //PULL PIN HIGH TO ASSURE OFF
}

void loop() {
 
if (BUTTON_COUNTER == 10){
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_RED, LOW);
Serial.println("10 steps, well done");
BUTTON_COUNTER = 0;
}
}

YOU DO LIKE YOUR CAPS, DON'T YOU? :wink: And hate indentation....

And a tip, if you use proper variable names, most statements become self explaining so you don't need to repeat yourself in the comment.

notsolowki:
here maybe this can help you get started

I don’t agree with giving a kid code for a school assignment when there is no evidence that the s/he has done any work him/herself. The kid will get a grade s/he has not earned.

Would you like to go to a dentist who cheated at med school?

…R

[off topic / not as comment / do agree with the statement!]
I don't want a dentist at all who did me school. I want a dentist who finished (cheating-less) dentist school :smiley: Might differ in other countries but here the two are not related :stuck_out_tongue:

im just trying to help. i dont see how looking at any other example sketch would be any different. besides, the code i gave them dont do anything its not complete.

notsolowki:
i dont see how looking at any other example sketch would be any different. [..] its not complete.

I think you gave your own answer :wink: The example is aimed to learn a principle and is all you need to learn it.

septillion:
I think you gave your own answer :wink: The example is aimed to learn a principle and is all you need to learn it.

i cant believe the question started with,

"I got an assignment. But we can't figure out how to do it. So the teacher asked us to ask some other people if they would know the answer."

obviously no teacher would ask you to ask someone for the answer.

notsolowki:
obviously no teacher would ask you to ask someone for the answer.

Maybe the teacher has nfc how to do the problem she or he set the class and can't actually teach them?

(In a PM to me, the OP did in fact indicate they are seeking turnkey code, not mere advice...)

They can, of course in exchange for legal tender, ask here. This board, and most others, is for advice and/or learning.

septillion:
They can, of course in exchange for legal tender, ask here.

There is nothing on the G&C board header that says tender (legal or other) need or even should or even might change hands. Why does everyone think that?

True, but I'm not crazy enough to do without something in exchange. Participating in a fun project gives fun/satisfaction in exchange. But when somebody just ask for code (school assignment or commercial product) I'm only willing to give that in exchange for money. And that's I think the general reaction on this forum.

You are of course free to do it without anything in exchange. But that does mark you as "crazy' in my book :wink:

Its

septillion:
But when somebody just ask for code (school assignment .... ) I'm only willing to give that in exchange for money.

Interesting that you wouldn't object to providing an answer for school work which the student would likely pass off as theirs without citing you, on ethical grounds but purely pecuniary ones.

You have no issue helping a student cheat, long as you make money out of it.

septillion:
I don’t want a dentist at all who did me[d] school. I want a dentist who finished (cheating-less) dentist school :smiley:

Fair enough - but they both involve blood and anaesthetics.

…R

Anyway fwiw I PM'd OP a working sketch. I'm not his or her conscience. But it would be interesting to see how, if at all, a student cites assistance from a forum and if they sign the common "own work" anti plagiarism box.

Also wondering how often a teacher picks up that students' solutions come from a forum?

Also visualising a dental student asking for help on a dental forum. Most replies would be "post the x rays" and "what did you try so far" and "is Google broken where you live?"

coffeeBean:
Its
Interesting that you wouldn’t object to providing an answer for school work which the student would likely pass off as theirs without citing you, on ethical grounds but purely pecuniary ones.

You have no issue helping a student cheat, long as you make money out of it.

Everything is relative and I’m not saying I’m not* weighing ethical grounds, but if someone is willing to pay me 1000 euros for something simple as this, yeah, I confess I would be guilty. Would not do it for beer money as that would apply if someone would ask gently for a hobby project.

  • Same as programming, not setting something does not mean clearing it either.

septillion:
I’m not saying I’m not* weighing ethical ground

I wasn’t judging btw: merely saying it was interesting.

I firmly believe a forum’s not a conscience; if I feel like supplying some turnkey code I will- it’s the recipient’s business what they do with that. (I just won’t charge for it :wink: (not that I have a mechanism for doing so) and if it’s such a big job that it cuts into my time too drastically I won’t do it anyway.)

coffeeBean:
Anyway fwiw I PM'd OP a working sketch.

Why not just post it in a Reply here so that other readers can benefit?

...R