Index \ Processing \ BasicX \ C A BasicX program is written in a flavor of the BASIC programming language. Large distinctions occur with the Wiring and BasicX syntax. Wiring is used to create programs that run in the Wiring hardware. BasicX is used to create programs that run on BasicX microcontroller. |
Wiring | BasicX |
int x = 70; // Initialize x = 30; // Change value |
Dim x as Integer x = 70 ' Initialize x = 30 ' Change value |
float x = 70.0; x = 30.0; |
Dim x as Single x = 70.0 x = 30.0 |
int[] a = {5, 10, 11}; // Create an array a[0] = 12; // Reassign |
Not available |
int a[8]; // Declare a[0] = 1; // Initialize |
Dim a(1..8) as Integer ' Declare a(1) = 1; ' Initialize |
Wiring | BasicX |
void setup() { void loop() { |
Sub Main () Do ' Statements Loop End Sub |
for(int a=45; a<=55; a++) { // Statements } |
Dim N as Integer For N = 1 to 10 ' Statements Next |
if(c==1) { // Statements } |
If(c=1) Then ' Statements End If |
if(c!=1) { // Statements } |
If(c<>1) Then ' Statements End If |
if(c < 1) { // Statements } |
If(c < 1) Then ' Statements End If |
if(c >= 1) { // Statements } |
If(c >= 1) Then ' Statements End If |
if((c >= 1) && (c < 20)) { // Statements } |
If((c >= 1) And (c < 20)) Then ' Statements End If |
if(c >= 20) { |
If(c >= 20) Then ' Statements 1 ElseIf (c = 0) Then ' Statements 2 Else ' Statements 3 EndIf |
Wiring | BasicX |
// Comment |
' Comment |
void doIt(int x) { // Statements } doIt(x); |
Sub doIt(ByVal x As Integer) ' Statements End Sub Call doIt(x) |
int square(int x) { return x*x; } square(X); |
Function Square( ByVal x As Single) As Single Square = X ^ 2 End Function Square(X) |
Wiring | BasicX |
Serial.println("hello world"); |
Debug.print "hello world" |
int a = 55; Serial.print(a, DEC); |
Dim a as Integer a = 55 Debug.print CStr(a) |
int a = 55; Serial.print("a is "); Serial.print(a, DEC); |
Dim a as Integer a = 55 Debug.print "A is "; CStr(a) |
Wiring | BasicX |
// digital output |
' digital output ' Define pin 0 as input. Const thePin as Byte = 0 ' Sets the pin 0 to HIGH. Call PutPin(thePin, 0) |
// digital input int value; // Define pin 16 as input. pinMode(16, INPUT); // Read the value of pin 16. value = digitalRead(16); |
' digital input Dim value As Byte ' Define pin 16 as input. Call PutPin(16, bxInputPullup) ' Read the value of pin 16. value = GetPin(16) |
// analog input int Voltage = 0; int thePin = 0; Voltage = analogRead(thePin); |
' analog input Dim Voltage As Integer Const thePin As Byte = 13 Voltage = GetADC(thePin) |
// analog output int thePin = 0; // Set pin 0 to 75 percent of full scale. analogWrite(thePin, 0.75*1023); |
' analog output Dim DACCounter As Byte Const thePin As Byte = 16 ' Set pin 16 to 75 percent of full scale. Call PutDAC(thePin, 0.75, DACCounter) |
// printing to the serial port void loop() { |
' printing to the serial port Private InputQueue(1 To 10) As Byte Private OutputQueue(1 To 30) As Byte Public Sub Main() Call OpenQueue(InputQueue, 10) Call OpenQueue(OutputQueue, 30) Call OpenCom(1, 19200, InputQueue, OutputQueue) Call PutQueueStr( OutputQueue, "Hello, world" & Chr(13) & Chr(10) ) Delay 0.5 End Sub |
// moving a servo motor to 90 degrees. #include "Servo.h" Servo myServo; void loop() { |
' moving a servo motor to 90 degrees. Sub Main() Const servoPin As Byte = 15 Do ' Generate a high-going 1.5 ms pulse. Call PulseOut(servoPin, 0.0015, 1) ' This is to produce a pulse rate of about 50 Hz. Call Delay(0.02) Loop End Sub |