BASIC to Arduino C: Arduino C programming for Basic Programmers Cheat Sheet

 

 

The Cheat Sheet

BASIC to Arduino C. Below is a short list of common C and BASIC functions. It is designed to take a BASIC programmer and get him started in Arduino C.

This is of course only a short list of the most common functions. More will be added to this web site in time.

------------------- BASIC TO ARDUINO C -------------------

Comments / Remarks / Telling the compiler to ignore a line

Basic:
REM
or
“ ‘ ” (a single quote)

Examples:
rem x = 3
‘ Ignore this comment.

C Language: double forward slashes “//”

Examples:
// x = 3;
// Ignore this comment.

Or

A forward slash “/”, and an asterisks “*”, followed by text, followed by another asterisks “*” and another forward slash “/”.

/*
This is a series of comments
Another comment
And another
*/

------------------- BASIC TO ARDUINO C -------------------

Indication of End of a Line
Basic: At the end of a line of code no special punctuation is required.

Examples:
x = 3
y = 4

C Language: At the end of a line of code a semicolon “;” is required.

Examples:
x = 3;
y = 4;

------------------- BASIC TO ARDUINO C -------------------

Variables (“Variants” for BASIC)
BASIC: use a variable and the system takes care of what kind of variable it is based on how you use it these super variables are called “variants”.

Examples:
X = 5 rem X is an integer.
Y = 5/2 rem Y is a real number.
Z = TRUE rem Z is a boolean number (logically true or false).


C: All variables MUST be declared BEFORE they are used as to how they will be used.
int X; // x is an integer.
Float Y; // x is a “float” ( a number with a decimal point—a “floating point” number to be exact.)
Bool Z;

------------------- BASIC TO ARDUINO C -------------------

Mathematics (for the most part it’s the same)
Basic: x = y/3
C Language: x = y/3;

------------------- BASIC TO ARDUINO C -------------------

Assignments (for the most part it’s the same)
Basic: x = 3
C Language: x = 3;

------------------- BASIC TO ARDUINO C -------------------

Comparison
Basic:
If x = 3 then y = true

If x = 3 then
Print “done”
Print “for now”
Else
Print “not done”
Endif

Others:
Not equals: <>
Less than: <
Greater than: >

C Language:
If ( x ==3) y = true;
// no “then” needed in C. Also note the DOUBLE equal signs ==

If (x == 3 )

{
y = true;
z = true;
}
Else
a=10;
End if

Others:
Not equals: !=
Less than: <
Greater than: >

Warning: Beware of accidentally using the single equal sign (e.g. "if (x = 10)" is WRONG, but "if (x==10)" is RIGHT!). This won’t result in an error, but will not be right. In the C language, a single equal sign ALWAYS MEANS ASSIGNMENT. A DOUBLE equals is used for comparison.

------------------- BASIC TO ARDUINO C -------------------

Counting / incrementing / decrementing
Basic:
x = x + 1
x = x-1

C Language adding 1 to x:
x = x + 1;
x = x + +;
+=x

C Language subtracting 1 from x:
x = x - 1;
x = x --;
-=x

------------------- BASIC TO ARDUINO C -------------------

Loops
Basic “for” loop:
For x = 1 to 4
Print “hello”

C Language “for” loop :
For (x=1; x<5; x++)
{
Println “hello”
}

------------------- BASIC TO ARDUINO C -------------------

Printing
Basic:
print x
print “hello”

C Language:
println( x);
println “hello”;

------------------- BASIC TO ARDUINO C -------------------

Concatenation
Basic:
x = “hello”& “world”

C Language:
x = “hello”, “world”

------------------- BASIC TO ARDUINO C -------------------

Structure

The structure of a BASIC program differs in a few different ways than that of a C program. See the examples below.

Remember: BASIC has "subroutines" and C language has "functions". Both work about the same. In Basic you use "gosub" to call a subroutine. In C you just use the name of the function.

In BASIC you can make infinite loops with "goto" statements. In C (on the arduino) you use "loop".

Examples:

Basic:

X = 3

Here
// your looping code goes here
gosub mysub
Goto here

Mysub
Rem do some stuff
return

C Language:

// Note: The word “void” you see at the start of most functions means that a function does not return any values.

int buttonPin = 3; // You need to initialize your variables before doing anything else.

// Note: the function below called “setup” is a function used to initialize variables, pin modes, start using libraries, etc. It runs only once. The function called “loop” will loop forever.

void setup()
{
Serial.begin(9600); // start writing outputs to console window
// your setup code goes here
}

void loop() // this code will loop forever. Just what we need for robots.
{
// your looping code goes here
}


BASIC to Arduino C: Click HERE to go to the official Arduino web site.



New! Comments

Have your say about what you just read! Leave me a comment in the box below.

Recent Articles

  1. Stu the AI Robot

    Jul 23, 16 12:26 AM

    Stu the AI Robot - Debugging

    Read More

  2. Best Game Camera Security Box

    Jul 07, 16 10:47 PM

    Camera stolen again? This is the best Game Camera Security Box on the market. It...

    Read More

  3. Robots and Androids

    Jul 03, 16 12:50 AM

    A site with information on robots and androids including their history, building them, and so much more.

    Read More

Robot-Android-Blog  Read our blog about robots, building robots, and easy robot building.

How to Build a Robot How to Build a Robot takes you through each step required to build a robot.

Build an Arduino Robot Yes you CAN! We get you started.

Robot Comics Robot Comics are HERE! We start off our comics with...

Virtual Steve Jobs Virtual Steve Jobs? Steve Jobs is gone and we missed him so much we re-created his essence in software...

The EZ Robot Review The EZ Robot Review. This article reviews the EZ Robot building system, the robot board and system for beginner's robot building.

Medical Robots Medical robots are now showing their silver faces in hospitals and doctors' offices across the world.

Roomba Repair Quick and Simple Fixes for Your iRobot Roomba vacuum

Roomba Batteries How to extend the life of your Roomba's battery. Buy replacement batteries here.

Robot Cars - Yesterday’s Vision, Today’s Reality Are robot cars 'on track' to becoming the way of the future? What issues are at stake at their current level of development?

Robot Car Safety - The Future of Today’s Vehicles

Robot Car Safety can be identified by two main technological components - lacking in human drivers -a (1) instant reaction time and (2) 360-degree awareness of the road.

Educational Robots Learn robotics with these educational robots..

Robot People Robotic replicas of people - robot people - are starting to pop up here and there. We even visit a company who is today making them to order.

Hacking Elvis - The Alive Elvis Animatronic Robot In these articles we show you how to run your Alive Elvis from a microcontroller such as the Arduino and the Basic Stamp. Hacking Elvis...

Wall-e toy robots from Disney Wall-e toy robots are still popular this year

R2D2 Toy Robot : Interactive-Astromech Droid Here's a review of the high-end R2D2 toy robot, the interactive astromech droid.

Toy Robot Dogs Toy Robot dogs: In the robot pet store, you will find toy robot dogs - robomuts if you will - of all sizes, shapes and prices.

Wowwee Robotics Wowwee Robotics has been building toy robots for years.

Lost in Space Toys : The Robot Lost in Space Toys : There have been scores of toys built resembling the Lost in Space Robot, sometimes call by his model number "B9"...

Tribot Robot The tribot robot is one of the most entertaining toy robots that has come from Wowwee...

Terminator Robots Terminator Robots : The Terminator movies and television show brought robots to...

Artificial Intelligence: Our Brain In That Small Chip Artificial Intelligence was once thought of as an impossible feat. Now, with modern advancements in robotic technology, machines can be made to think like humans.

R2D2 - An Adventurous, Resourceful, and Loyal Robot R2D2 demonstrates several notable characteristics every human can learn from, in spite of the fact that he is, a robot. Read his biography here.

Anybots Vistual Assistant Robots - The Coming of Age in Telepresence Robotics Anybots Virtual Assistant Robots are expected to grow in a few years, or perhaps sooner.

BlueBiped: Propelled by it's Own Weight BlueBiped uses no power source to walk. This robot has set a Guinness World Record, walking nonstop for a distance of 15 km (9.32 miles), the longest distance ever walked by a bipedal robot

EZ-Robot May Be the Easiest Way to Build a Robot EZ-Robot May Be the Easiest Way to Build a Robot. The EZ-Robot is a $235 kit that includes everything you need to transform one of your old toys into a functional robot.

Introducing MorpHex, a Spherical Hexapod Robot Introducing MorpHex, a Spherical Hexapod Robot. Imagine a robot shaped like a ball which transforms into a walking six-legged contraption. That’s a description of MorpHex, created by Kare Halvorsen.

Recovering Kids Monitored by Robots After Surgery Recovering Kids Monitored by Robots After Surgery. A Boston, Mass. hospital introduces a sci-fi worthy caregiver system, where patients can go home and stay monitored by robots after surgery.

iCub the "Baby Robot" - Learns to Crawl Like a Baby Have you heard of the iCub? It is a one-meter high android originally developed by the Europe-based RobotCub Consortium. The iCub strongly resembles

Dongbu Robot HOVIS Kits Allow Users to Build An Android Phone Powered Robot Dongbu Robot HOVIS Kits Allow Users to Build An Android Phone Powered Robot

Search
Robots and Androids

Bing

CLICK HERE

to read about the

ROBOT COLLEGE

Build an Arduino Robot!

Get the ebook.

Only $.99!