Converting C to BASIC?

kmcderm133

New Member
I'm trying to duplicate a project I found on Instructables.com, and I chose the PICAXE 08M for a micorcontroller, as it runs on BASIC, which is the only programming language I've had even remote success in. Unfortunately for me, the creator of this project used a chip that works in C. Song files are used to give patterns or maybe seeming randomness to the lighting of LED's. Is there a way to convert C to BASIC, or would it be easier to start from scratch and write my own "songs" for flashing patterns?

Thanks,
Kevin
 

eclectic

Moderator
Very quick reply.

Your option number 2 seems a good way to start.

You could use the simulator to play with the output patterns.

e
 

Dippy

Moderator
Well there won't be anything to convert it 'automatically' (magically) if that was what you were hoping for.
Obv it depends on the code but C has so much more 'control' and much more variable space etc. so that you may be hard pushed to find a PICAXE 'equivalent' and you'd have to be experienced in both to convert efficiently where possible.

If you understand C vaguely you may be able to use it as a guide to writing your own.

I know nothing about the software you mention and unless hippy is at a loose end (or should I say 'lose end' on this forum) then think of Plan B. A software conversion may be near/completely impossible or it may be tweakable.

Without seeing the code (and please don't PM it to me) I couldn't say for sure.
 

hippy

Technical Support
Staff member
It all depends on the scale and scope of the C-based project. It could be a bit like, "Ferrari have published their plans for their F1 racer and I've got stacks of planking in the shed, so how do I convert those plans ?".

The best approach I'd say in all cases is to take the essence of what the project is and then re-design from scratch. It's usually quite hard to translate one language into a direct equivalent. I do that in some of my own developments for the PC, but that only works because it's going from lowest denominator upwards. With C to PICAXE it's working the other way.

Another approach, having decided you like what you've seen, is to forget all about how it was done and decide what you want and then set about achieving that without considering the other project beyond using it as the source for ideas and clever tricks it may include.
 
Last edited:

Mycroft2152

Senior Member
K,

What's the project / instructable?

It may be something that someone has already done, or has done something similar.

Myc
 
Last edited:

BCJKiwi

Senior Member
There is always the 08M TUNE command which will automatically flash the LED (or 2) in conjuction with sound output. Would that suffice?

See Page 169 Manual section 2
 

kmcderm133

New Member
Thank you for your speedy replies! :) It seems the best way to proceed would be to reverse-engineer the C code. So, I have my work cut out for me. :D The project is Jar of Fireflies. I've got enough parts for five or six of them, so I'm kinda comitted to it at this point... Here's the link: http://www.instructables.com/id/Jar-of-Fireflies/ I have to download the PICAXE VSM software yet. I hope it'll help. :)

-Thanks,
Kevin
 

moxhamj

New Member
Yikes, half of that is in machine code.

A 14M picaxe can handle the hardware side. Maybe an 08M if you want to be clever with charlieplexing but a 14M would be simpler.

I very much suspect the picaxe code will end up shorter. Just need to replicate the code. This is a good example of using "top down programming".
 

Dippy

Moderator
Well, I haven't bothered looking at code but if, as DrAc says, it has a lot of machine code then ooeerr.
If it is really annotated assembler then you may be able to follow the routes remembering that actual PIC programming gives control/access to many things that PICAXE Basic can't. (Yeah, yeah Poke etc.).

I hope you do the project as it looks mighty purddy. I also hope you can find someone with several spare hours to help you with the code conversion.

Personally, I'd write it from scratch and show it as a Finished Project as opposed to a 90%-copied project.
 

Rickharris

Senior Member
From a look at the Utube the LEds are fading in and out in a random way. The video isn't long enough to check the claim to use real bug data. AFAIK fire flies will after a while syncronise their flashing. This is one of their features - other than that I would start with getting to grips with charlyplexing depending on how many flies you have in the jar and the random function perhaps with a random seed such as light level to keep the sequence pretty random.

After that try just blinking the leds on and off in random sequences and see if that satisfies your desires.

By the way if you live in the UK may/june is firefly activity time and they can bee seen if you know where to look. We get them around here (lincolnshire) , dim green flashes that generally occure at the edges of your vision and never where you happen to be looking.
 

Mycroft2152

Senior Member
K,

Look down in the comments, you'll see that the "Jar of Fireflies" has already been converted to PIXCAXE by Botronics. It also has been discussed here on the forum by yours truly. Try a forum search.

I've built a half dozen of them so far. great project.

Myc
 

eclectic

Moderator
To get started, free and very quickly,

There are two programs in the Samples folder (accessed from the Programming Editor)

BAS100 STAMP LED tester. bas

AXE103 Safety Light .bas

The first will run in 20M mode.

Try them in the Programming Editor Simulator.

After, introduce some pauses.

It's not Fireflies, but it's pretty, and the programs are great for learning.

Finally, search, using the term

Firefl*

e
 

kmcderm133

New Member
K,

Look down in the comments, you'll see that the "Jar of Fireflies" has already been converted to PIXCAXE by Botronics. It also has been discussed here on the forum by yours truly. Try a forum search.
D'oh!

Dippy, I don't want to present the project as being mine, I didn't conceive the idea. The only real change I'm making is that it will be solar. And the reason for using a PICAXE instead of the controller Keso used is that they're SO much cheaper to buy AND use, and they use BASIC! :) I don't know if I mentioned this before or not, but I'm much more of a 'hardware guy' and I don't do very well with software. (come to think of it, I was never very good with human languages either.) So, BASIC is probably as far as I'll get without some serious time devoted to the subject. :( Charlieplexing isn't really a problem for me. I'm aware of the principles as far as the hardware goes, just have to figure out how to do it with software. (Having one pin go High, the other Low, and then have them switch.) The BASIC stamp was very good at this, but it takes too many components to make it work, and the pre-made boards are a bit too big. :( So, it's on to a quest for better code, and such. Wish me luck! :)

-Thanks again,
Kevin
 

moxhamj

New Member
Sounds a fantastic project. I like the solar idea. Are you going to use a single nicad with a stepup or 3 in series? And do you have some solar panels? With super efficient leds (like the ones in solar garden lights) you can run them with very little current. Indeed, a cheap and simple source for some components could be 3 solar lights. 3 batteries. 3 solar panels - connect them up in series. Use one of the reverse voltage diodes - leave the other 2 out. Use the leds for the fireflies. Very cheap for what you get.
 
Top