Simple Program

Ok, i’ve finally gotten to reading the Basic Atom manuel (after finding i have absolutley nothing else to do) and i have entered the simplest program they have given me, and it is to create a blinking LED heres the progam

Main High P0 Pause 200 Low P0 Pause 200 End

i connect the LED and it turns on but it is only solidly lit, not blinking like the prgram says it will

any body have a clue to wat could b happening? ill be working on it

does it turn off?

you don’t have a loop structure to make it blink on and off. This code will make it blink on and off:

Loop:
High P0 
Pause 200 
Low P0 
Pause 200 
goto loop

actually, after reading my manual, pause takes in the number of _milli_seconds you want the chip to wait, so you are basically doing .2 seconds. My guess is that your circuit is backwards where the LOW output will cause the LED to stay on.

Try this:

Loop:
HIGH P0
Pause 2000
LOW P0
PAUSE 2000
goto Loop

and make sure your circuit is set up so that HIGH causes the LED to go on. This will blink the LED at a period of 4 seconds, with 2 second on and 2 second off times.

Let me know if you have any questions on how to set the circuit up properly.

Mike D

YUP thats wat it was mdiv, it works, as we speak im playing with differen’t times and stuff

Awesome!

You can also make an LED blink using the PWM function, without using a loop structure (it won’t last forever however as you set the number of cycles the PWM waveform will last). It’s a good next step as the PWM function can be used to do a whole lot more than blink LEDs, ie control a motor controller which then controls motor speed.

On my eyecon I’m using a similar function to PWM on the basic atom pro to drive the scorpion which in turn drives my motors.

im sorry Mdiv, but what is PWM function?

you could point me out to where it is in the manual if you do not want to explain it

Page 96 of the user manual:

PWM pin, period, duty, cycles

PWM P0 2000000, 1000000, 10

This program outputs a waveform that has a 2 second period, 50% duty cycle (1 second on, 1 second off) and does 10 of those periods in a row. The PWM command takes in time in micro (10E-6) seconds, so 2,000,000 microseconds = 2 seconds, etc.

Try it out with your LED circuit =)

sounds pretty cool, ill checkit out right away :smiley:

ok, i finally found it in the book, i must be reading a different manuel, mine is off the mirco website (or whatever it is) but i like it, cause it allows you to certain I/0 time for a set amount of time, like you said

wow, as i get more in depth with the Mbasic programing i find that it is becoming easier and easier to understand :laughing:

ok, as this post suggests i’ve been learning simple programs and going through the programming manual, well i have a code to make it do a certain sequence of solids and flashing, and when i use the debugger, it works fine, but when i program the Basic Atom with it, it doesn’t work :angry: , it goes solid for 3 seconds, then turns off, then is solid for 1 second, then it turns off, and thats the end of the program

heres the code: [code]timer var byte
LED con P0

Start:
gosub Solid
gosub Slowflasher
gosub Solidfunny
goto ENDPROG

Solid:
High LED
Pause 3000
Low LED
Pause 3000
return

Slowflasher:
for timer=0 to 20
Toggle LED
pause 10
next
return

Solidfunny:
High LED
Pause 1000
Low LED
Pause 1000
return

ENDPROG:
end [/code]

please tell me if something is wrong with it, meanwhile i think i saw something about timing when using the debugger and actually programming your basic atom with it, ill let you guys know if i find it

ok this is what i found

thats all the manual said about this sorta thing, :open_mouth:, and i dont think that would cut out one whole piece of my program

can anyone shed some light on the situation?

-Jared

Jared,

The PAUSE command in the slowflasher is only set for 10 milliseconds, so basically it does 10 on-off pulses with a period of 20mS, which is like 0.02 seconds, so the whole on-off-on-off-on-off…etc waveform is 0.2 seconds long, hard to see…

Try playing with the value after PAUSE in the Slowflasher section (try a large number like 1000 mS, aka 1 second) and see what your results are.

I think it is just happening too fast (thus the routine name “slowflasher” is a bit…misconstrued =) )

Cheers,

Mike D

ok, ill check that right now

yea, thats wat was wrong Mike, i also changed the code so it loops, i only had it going so fast because my brother challenged me to write a code that had a flasher that would flash 20 times in 2 seconds so that would mean i needed it to flash 10 times a second, but now that i think about it, idk if i did the math right :laughing:

[code]timer var byte
LED con P0

Start:
gosub Solid
gosub Flasher
gosub Solidfunny
goto Start

Solid:
High LED
Pause 3000
Low LED
Pause 3000
return

Flasher:
for timer=0 to 10
Toggle LED
pause 100
next
return

Solidfunny:
High LED
Pause 1000
Low LED
Pause 1000
return

[/code]

2 seconds / 20 repetitions = .1 second per repetition
Therefore, you needed a pause of 100 to do that.