Showing posts with label basic. Show all posts
Showing posts with label basic. Show all posts

Wednesday, February 4, 2015

Robot Club - fourth session completed


Link to Preparing post details in the parts in the kits.: http://winkleink.blogspot.co.uk/2014/11/preparing-for-2015-after-school.html

Link to First session; http://winkleink.blogspot.co.uk/2015/01/robot-club-first-session-completed.html

Note; I did not post for the second session. There is a short summary in the Third Session post.
Link to Third session: http://winkleink.blogspot.co.uk/2015/01/robot-club-third-session-completed.html

This week we nearly had a full house.
Only 1 child missing due to illness.

The 4 who attended the previous week remember a lot of their work and code so were getting stuck into getting their robots to go around a corner.

I had a bit more fun getting drivers on enough school PCs to permit the Arduino Nano to be seen. It needs custom USB/Serial drivers that are not included by default.

The teacher who is ICT coordinator came in to see the session in full swing with robots spinning, or moving along the floor. With coding going on and due to plus and minus lines on the batteries being shorted a nice little display of black smoke and the lovely smell of burnt plastic.
No real harm done just a jumper wires plastic sleeving was melted.
I congratulated the child on making smoke as it's something we all do when we work with electronics.  They were kind of shocked.
It was great that the teacher had the same attitude so no harm done and no concern about burning down the school.
I tested their robot kit and Arduino. Nothing damaged, amazingly so did a little bit of rewiring and handed them back their robot to get working on again.

On of the kids who was in the previous session had a problem where their robot was pulling to the left.  These are small cheap kits so the motors aren't tuned and the wheels are small and have grip meaning they catch on the carpet.  Meaning they cannot reliably go straight.
We tried to fix it by turning the wheels in or our to change the resistance but no go so introduced that child to analogWrite.
A value of 235 seemed to make it all work perfectly. They had a nice straight running robot.

Once again the kids were not that eager to leave as they were perfecting their code and making it better.

At the end one of the girls who was being collected wanted to show her mother what she had done so she gave a great demonstration of her robot.  Holding down reset to stop it moving.
Set it up and let it go. She then explained the code she had made as well as giving details on some of the other parts we will be using.

Next week we will be using an input device. A small line following sensor. I will mark the edge of the room area with white paper providing a contrast with the blue flooring. The idea will be to detect the paper and make the robot turn.
This will be the first time the kids do inputs and will also require the introduction of the 'if' statement.

Looking forward to another productive session next Monday.

Thursday, April 19, 2012

Prime Numbers

I was watching the video below and I spotted that the Benchmark BM9 is getting Prime Numbers. 

 

This reminded me of a program I wrote in 1986 (20 I'm old years ago) to work out Primes on an Apple ][ in school.
So, I just had to fire up a BASIC interpreter (BASIC-256) to see if I could recreate it again.
Below is the code I did today with loads of REM comments to explain what I did.

REM Printing the Prime numbers up to 10,000 (maxcheck)
REM Winkleink - 2012
REM Just print the 1st 3 Primes
print 1
print 2
print 3
REM x is what we are checking set x to the next biggest odd number
x=5
REM number up to which we will check for primes
maxcheck = 10000
while x < maxcheck
REM Start the checking with 3 as 1 isn't valid and we are only checking odd number
i = 3
REM Set indicator if prime to 1 (means prime)
isprime =1
REM We only have to check odd numbers up to the Square Root of X as any number that will divide into X evenly will be made up of a number below SQR(x) and 1 above SQR(x)
while i <= int(sqr(x))
REM Check not Prime by seeing if there is a remainder if there is no remainder set isprime to 0
if x/i = int(x/i) then isprime=0
REM If not prime then set i to be above the while loop
if isprime = 0 then i= int(sqr(x))
REM Increment i by 2 as only need to divide by odd
i = i +2
endwhile
REM If isprime is still 1 then it is a prime number
if isprime=1 then print x
REM Increment x by 2,again even numbers won't be prime
x = x +2
endwhile

It was great fun to do and really brought back memories of sitting in the computer room in school watching as it slowly printed out the results.  A bit faster today.

And here is a video of it working.


 
As always.  Code is rough and just done for fun.  If you know a better way to calculate primes let me know in the comments.