Arduino Functions and Commands
Arduino Functions and Commands
var = 0;
while (var < 200) {
// do something repetitive 200 times
var++;
}
b. Array
i. consecutive group of memory locations that are of the same type. To refer
to a particular location or element in the array, we specify the name of the
array and the position number of the particular element in the array.
void setup () {
void loop () {
for ( int i = 0; i < 10; ++i ) // initialize elements of array n to 0 {
n[ i ] = 0; // set element at location i to 0
Serial.print (i) ;
Serial.print (‘\r’) ;
}
for ( int j = 0; j < 10; ++j ) // output each array element's value {
Serial.print (n[j]) ;
Serial.print (‘\r’) ;
}
}
c. String Array -
i. The string is a data type that stores text rather than the integer values.
ii. The string is an array of characters or a set of characters that consists of
numbers, spaces, and special characters from the ASCII table.
void setup() {
Serial.begin(9600);
void loop() {
Serial.println(StrAB[i]);
delay(1000);
d. String Variables
i. are typically stored as arrays of chars, terminated by a null byte
e. String Literals
i. string of characters enclosed in double quotes, such as "To err is human
- To really foul things up requires a computer."
ii. are stored in C as an array of chars, terminted by a null byte
iii. are stored in C as an array of chars, terminted by a null byte
iv. may contain any valid characters, including escape sequences such as
\n, \t, etc. Octal and hexadecimal escape sequences are technically legal
in string literals, but not as commonly used as they are in character
constants, and have some potential problems of running on into following
text.
Include the definition and function of each and a sample code. Don’t forget to
include the reference at the bottom of the page.
2. Make a research of a basic code for creating/coding a program of “Turn on LED while the
button is pressed”.(Full program code must be provided.)
int ledflag=0;
void setup() {
pinMode(button,INPUT);
pinMode(led,OUTPUT);
digitalWrite(led,LOW);
void loop() {
if (digitalRead(button)==HIGH){
if (ledflag==0) {
ledflag=1;
digitalWrite(led,HIGH);
else {
ledflag=0;
digitalWrite(led,LOW);
delay(1000);
******Don’t forget to make a copy first. Do not edit the file. Thank you*******
Sources: