Raspberry Pi system command.

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

mnf
Valued Contributor
Valued Contributor
Posts: 540
Joined: Wed May 31, 2017 11:57 am
Has thanked: 53 times
Been thanked: 300 times
Contact:

Raspberry Pi system command.

Postby mnf » Sat Oct 06, 2018 9:00 am

One for Raspberry Pi users:

Was thinking about unzipping a file on the Pi - using Flowcode.. That would be a big project and madness unless you had )a lots of time and b) someone was paying big bucks and c) lots of (hard) work.

So the easy way is to use someone else's code. The good news is that this is straightforward.

Use the 'system' command in a C macro.

So for example:

Code: Select all

system("mkdir test");      // Create a new directory 'test'


or

Code: Select all

system("gunzip file.gz");   // Unzip file.gz


This only works for Pi users (at present) - where the underlying OS has commands available. To make things more general - build and use a string variable and then: (take a peek at the C code to get the variable names FC has used)

Code: Select all

system(FCV_S);   // Use global string S as a command....


Martin
These users thanked the author mnf for the post (total 2):
Benj (Tue Oct 09, 2018 10:59 am) • jgu1 (Fri Nov 01, 2019 6:51 am)
Rating: 10.53%
 

mnf
Valued Contributor
Valued Contributor
Posts: 540
Joined: Wed May 31, 2017 11:57 am
Has thanked: 53 times
Been thanked: 300 times
Contact:

Re: Raspberry Pi system command.

Postby mnf » Fri Nov 01, 2019 12:40 am

Happy Halloween to you all..

A Flowcode Haunted House Project....

This was supposed to have been a weekend project - but building the house itself took a lot of time. It is from Matt Bergstrom's 'Cut and Assemble' haunted house book - and the result is a nicely detailed model. There is plenty of room inside for 'wiring' and gubbins. However it is 'paper' and some reinforcement might have been a good idea. I rather ran out of time and only installed 5 LEDs for room lights. I might add more later to the lower rooms - but the upper stories would be harder.

I initially intended to use an Arduino with a sound shield - but because I wanted to play multiple sounds at once and also trigger the lights whilst sounds are playing - I opted for a Raspberry Pi3. The display is self contained and uses a battery pack and cordless speaker for the sound. I'd intended to use a coin slot for starting the display - but ended up using an illuminated button (FC has one - but doesn't seem to have a way to turn the LED on and off - so used separate components..) due to lack of time.

Flowcode - made the actual coding very easy (I didn't have much time to meet the Halloween deadline.) I downloaded some sound effects from SoundBible - and found a 'creepy' tune on my laptop (from a game - just not sure which) I used WinSCP to transfer files to the Pi - FC also worked beautifully with Pi working 'headlessly'. I added a line to /etc/rc.local to run the program on boot too.

I did this to try and raise some money for a local appeal - but if I'd had some more time I'd have randomised the effects and added some extra sounds, lights and possibly movement with a servo or a solenoid....

Original plan was also to install inside fishtank (inverted) for protection mainly - but with LED strip lights in the corners providing additional illuminations. I used an ULN2803 chip to control the 12v lights via the Pi...

Oh - and I used the system command to play the sounds....

Video at https://youtu.be/GucuKIzmpHQ - now uploaded....

pi1.fcfx
(27.97 KiB) Downloaded 9 times


Martin
Attachments
GOPR3643.JPG
GOPR3643.JPG (136.56 KiB) Viewed 277 times
These users thanked the author mnf for the post (total 3):
jgu1 (Fri Nov 01, 2019 6:51 am) • LeighM (Fri Nov 01, 2019 8:31 am) • Benj (Mon Nov 04, 2019 6:03 pm)
Rating: 15.79%