Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Programming the BeagleBone

You're reading from  Programming the BeagleBone

Product type Book
Published in Jan 2016
Publisher
ISBN-13 9781784390013
Pages 180 pages
Edition 1st Edition
Languages

Table of Contents (21) Chapters

Programming the BeagleBone
Credits
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
1. Cloud9 IDE 2. Blinking Onboard LEDs 3. Blinking External LEDs 4. Controlling LED Using a Push Button 5. Reading from Analog Sensors 6. PWM – Writing Analog Information 7. Internet of Things with BeagleBone 8. Physical Computing in Python 9. UART, I2C, and SPI Programming 10. Internet of Things using Python GPIO Control in Bash BeagleBone Capes
Pinmux and the Device Tree Index

Hello World program


Let's do a quick and dirty Hello World JavaScript program. In this program, we are just printing Hello World in the console view provided by Cloud9:

  1. Go to the File menu. Click on the New File button. You will see a new code editor tab opened with title Untitled1.

  2. Write the following code in the code editor view:

    // My first hello world program.
     console.log("Hello World");

    Tip

    Downloading the example code

    You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

  3. Go to the File menu again and save as hello.js. Now, you should see the tab title is changed from Untitled1 to hello.js. Now Cloud9 knows this is JavaScript program. It will highlight the program with different colors.

  4. Click on the run button at the top of screen. You will see the Debugger toolbar from right side is expanded to the Debug pane. Click on the Resume button on expanded pane or press the F8 key. You should see the Hello World text in the output view at the bottom.

Explanation

In this tiny code, the first line is the comment. JavaScript supports C and C++ style commenting. So the pattern /* ... */ is used in multi-line commenting and the pattern// is used for single line commenting. The second line is calling the log() method on the object console. We have given the string Hello World as a parameter to the log() method. A semicolon ; denotes a terminated statement. Here, the console object provides access to the browser's debugging console. console.log() is a method to print string. It prints Hello World in the console.

As we are using a built-in JavaScript object, we have not loaded a JavaScript module/library. You can try more methods provided by the console object. You can get a detailed document about JavaScript at: http://www.w3schools.com/js/ and https://developer.mozilla.org/en-US/docs/Web/JavaScript.

You have been reading a chapter from
Programming the BeagleBone
Published in: Jan 2016 Publisher: ISBN-13: 9781784390013
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}