Changing Hertz of LED

Hello, I am trying to do an assignment for a class and I am stuck.

I have to change a 1 Hz to 2 Hz and I cannot figure out how,

this is the coding for 1 Hz

void setup() { pinMode(2,OUTPUT); }

void loop() { digitalWrite(2,HIGH); delay(500); digitalWrite(2,LOW); delay(500);

}

Do I have to change the PWM? Or....

Thanks for all your help!

You want it to go twice as fast, so change the delay to 1/2 as much.

koalek: Hello, I am trying to do an assignment for a class and I am stuck.

I have to change a 1 Hz to 2 Hz and I cannot figure out how,

this is the coding for 1 Hz

void setup() { pinMode(2,OUTPUT); }

void loop() { digitalWrite(2,HIGH); delay(250); digitalWrite(2,LOW); delay(250);

}

Do I have to change the PWM? Or....

Thanks for all your help!

I'd love Australia to adopt Arduino as a teaching aid at schools here .

It couldn't me more obvious that this is a school assignment. Why do you do the work for the student instead of telling that student how to work it out (as was already done by CrossRoads) ? If you'd love to have schools use Arduino, you like to have people learn from it. Teaching isn't done by doing the work for a student, but having that student figuring out how to do it himself.

The answer was already provided.

No the answer wasnt givn- a "Hint" was given. Possibly a big hint, but for the simple question here, I have a hard time thinking of how to make it smaller, without being in closer dialog with the student.

Msquare: No the answer wasnt givn- a "Hint" was given.

Nope. The answer is clearly visible on this page...

Are we talking about the same thing? My understanding was 1) OP asks about getting his blink going at 2 Hz rather than 1Hz 2) CrossRoads says "change the delay to 1/2 as much" 3) cjdelphi shows the actual code (having replaced 500 with 250) 4) MAS3 objected to providing the finished answer (after all, now it is just a matter of typing in the answer without understanding anything) 5) cjdelphi said was already there 6) I agree with MA3/CrossRoad, and disagree cjdelphi. I also think "change the delay to 1/2 as much" is a BIG hint, but for the simple question it is hard to more subtle without starting to speak in riddles.

So before 3) above the answer was not on the page, which is what I agree with MAS3 on.

But - it is a tiny matter. I have not investigated if any of the posters do what the do often.

I do teach (occasionally; professional courses in specific software applications) and whenever a student asks a questions that is not a simple factual one, I do try and think of all the misconceptions that prompted the question.

In this case, I might have first checked if the student realized that Period(frequency) = inverse-of interval(duration). By then asking him/her about what defined the duration in this code, they might have come to the conclusion that the delay needed to be shorter. Secondly I might have asked what the OP meant by "PWM" at the end? (I still wonder why that was an afterthought in the question - there may have been a total mixup in the students mind - due to the course material - between analog and digital write, a blinking LED and a dim LED (which is blinking to achieve the effect...) )

A sufficient answer was provided indeed, so no need to reply anyway. But an answer is something completely different from a corrected sketch, ready to copy / paste. OP could have learned a bit, figuring out how to make these changes in his sketch, as was his assignment. I think people who are here on a daily basis, and have more than a few posts, should be aware of students trying to cut the curve and have others work out their assignments. A student might need help, but to work out an assignment is not going to teach anything. And that starts with the small assignments like this one.