Shop OBEX P1 Docs P2 Docs Learn Events
Homework Assignment — Parallax Forums

Homework Assignment

dcar2013dcar2013 Posts: 1
edited 2013-07-16 11:32 in BASIC Stamp
Build a circuit and write a program that will have a red LED (representing a power on light) blink once a second. Have 2 pushbuttons connected in such a way so that when button # 1 is pressed a yellow LED flashes at 20 Hz. When button # 2 is pressed a green LED flashes at 40 Hz. When both pushbuttons are pressed at the same time have the green and yellow LEDs flash alternately at 10 Hz. My problem is that I have the program for the red LED works properly and the program for the green and yellow works properly individually. But, when combined the buttons pressed simultaneously are not flashing alternately at the required durations. See attachment for code

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2013-07-15 12:36
    Welcome to the Forums.

    Not too many of us are fans of doing other people's homework.

    At a minimum, add some comments to your code so those who want to give hints can direct you to the relevant parts.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-07-15 13:02
    The Stamps can do only one thing at a time. When people have to accomplish multiple overlapping tasks like in your case, you want to look for a common time "tick" so the whole program operates in that cycle. Some cycles will cause one action to be done, other cycles may cause something else to be done. Sometimes an action may occur every other cycle, etc. If you were going to design your program with this scheme, how would you describe the timing and testing in terms of a time "tick"?
  • tonyp12tonyp12 Posts: 1,951
    edited 2013-07-15 13:13
    That RED LED should still flash at its own speed all the time will add a different way of programming, more like a state machine
    I see a time pattern with 10,20,40 hz so maybe

    PAUSE 10
    x=x+1
    if x>=40 then x = 0
    if x=??? and in3=???...........................
    and so on
    LOOP
  • ercoerco Posts: 20,257
    edited 2013-07-15 14:42
    That is a FUN assignment. Much better than the stuff I had to do in school way back when. Savor it, have fun and remember what you learn!

    If you take an honest stab at it, show some effort, and ask for help, we are happy to nudge you in the right direction. But we can't write your program for you.

    Unless you have a LOT of money. :)
  • GenetixGenetix Posts: 1,754
    edited 2013-07-16 11:32
    Look at Activity #4 in Chapter 3 of What's a Microcontroller. (Page 73 in V3.0, Page 56 in V2.2)

    You should comment your code so it's easier to read. Commenting is discussed in Activity #2 (Page 37 in 3.0, Page 46 in 2.2)

    Currently you don't have anything for the Red LED and your timing is not correct. Look at Activity #2 and see what PAUSE times are used for different blinking rates.
Sign In or Register to comment.