• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoArduino-ish ProgramGPIOPull the rope to blow the train whistle (implement ...
Previous Next

Pull the rope to blow the train whistle (implemented by pcDuino3)

Posted by: admin , October 27, 2014

Tinkermill’s TinkerScouts will install a decorated train at Roosevelt Park in Longmont. Steve Elliott came up with an idea that when kids pull the rope, it swings in front of the infrared detector.  When pcDuino detects the digital output from the infrared detector, it will use the system call function right inside the Arduino-ish sketch code to call the mplayer to play back a train whistle mp3 file.

 

The setup is as below:

1027_1

 

 

The infrared sensor is connected to pcDuino3 in the following way:

  • Red-> 5V of pcDuino3
  • Black -> GND of pcDuino3
  • Yellow -> Digital 2 of pcDuino3

 

Before we move to the Arduino-ish coding, lets follow this post to install mplayer on pcDuino3.  The mp3 file for train whistle can be downloaded here.

 

Open the built-in Arduino IDE on pcDuino, copy and paste the following code:

int ropepull=2;

void setup() {

  // put your setup code here, to run once:
  pinMode(ropepull, INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
 
  int pullstatus=0;
 
  pullstatus=digitalRead(ropepull);
 
  if(pullstatus==0) {
    system("mplayer /home/ubuntu/train-whistle-01.mp3");
  }

}

When it runs, we get the following:

 

If we want the code to start automatically after reboot, we can follow this post.

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors