Presentation is loading. Please wait.

Presentation is loading. Please wait.

Suleyman Demirel University 20151 CSS340 Microprocessor Systems – Lecture 1 Getting Started to Arduino.

Similar presentations


Presentation on theme: "Suleyman Demirel University 20151 CSS340 Microprocessor Systems – Lecture 1 Getting Started to Arduino."— Presentation transcript:

1 Suleyman Demirel University 20151 CSS340 Microprocessor Systems – Lecture 1 Getting Started to Arduino

2 Suleyman Demirel University 20152 Different Types  Arduino Uno  Arduino Mega  Arduino Nano  Arduino Leonardo  Arduino Micro  Arduino Nano  LilyPad Arduino  21 different Arduino types MicrocontrollerATmega328 Operating Voltage5V Input Voltage (recom)7-12V Input Voltage (limits)6-20V Digital I/O Pins14 (6 PWM) Analog Input Pins6 DC Current per I/O Pin40 mA DC Current for 3.3V Pin50 mA Flash Memory32 KB (0.5 KB bootloader) SRAM2 KB EEPROM1 KB Clock Speed16 MHz Length68.6 mm Width53.4 mm Weight25 g

3 Suleyman Demirel University 20153 Arduino Uno Board

4 Suleyman Demirel University 20154 Arduino IDE  Connect your Arduino board to your computer using the USB cable  Select Tools → Board from the drop-down menu and select the name of the board you have connected  Select Tools → Serial Port  Click on the upload button

5 Suleyman Demirel University 20155 Making the Sketch  Serial.println(value); Prints the value to the Serial Monitor on your computer  pinMode(pin, mode); Configures a digital pin to read (input) or write (output) a digital value  digitalRead(pin); Reads a digital value (HIGH or LOW) on a pin set for input  digitalWrite(pin, value); Writes the digital value (HIGH or LOW) to a pin set for output

6 Suleyman Demirel University 20156 Hello World

7 Suleyman Demirel University 20157 Hidden Treasure int main(void) { init(); // initializes the Arduino hardware setup(); for (;;) loop(); return 0; }

8 Suleyman Demirel University 20158 Arduino data types

9 Suleyman Demirel University 20159 Using Floating-Point Numbers float value = 1.1; void setup(){ Serial.begin(9600); } void loop(){ value = value - 0.1; //reduce value by 0.1 each time through the loop if( value == 0) Serial.println("The value is exactly zero"); else if(fabs(value) <.0001) //function to take the absolute value of a float Serial.println("The value is close enough to zero"); else Serial.println(value); delay(100); } OUTPUT: 1.00 0.90 0.80 0.70 0.60 0.50 0.40 0.30 0.20 0.10 The value is close enough to zero -0.10 -0.20 This is because the only memory-efficient way that floating-point numbers can contain the huge range in values they can represent is by storing an approximation of the number. The solution to this is to check if a variable is close to the desired value.

10 Suleyman Demirel University 201510 Working with Groups of Values

11 Suleyman Demirel University 201511 Arrays  Arrays are zero indexed, with the first value in the array beginning at index number 0. An array needs to be declared and optionally assigned values before they can be used. int myArray[] = {value0, value1, value2...}  Likewise it is possible to declare an array by declaring the array type and size and later assign values to an index position int myArray[5]; // declares integer array with 5 positions myArray[3] = 10; // assigns the 3rd index the value 10  To retrieve a value from an array, assign a variable to the array and index position: first = myArray[0]; // this is the first element last = myArray[4]; // this is the last element

12 Suleyman Demirel University 201512 Strings  String message = "This string"; //C++ type strings message.length() //provides thenumber of characters) in the string message.concat(anotherMessage) //appends the contents of anotheMessage to message (also + operator) message.substring(s, e); //returns a substring starting from s till e You can use the indexOf and lastIndexOf functions to find an instance of a particular character in a string  char message[8] = "Arduino"; //C type string int length = strlen(message); // return the number of characters in the string strcpy(destination, source); // copy string source to destination strcat(destination, source); // append source string to the end of the destination string if(strcmp(str, "Arduino") == 0) // do something if the variable str is equal to "Arduino"

13 Suleyman Demirel University 201513 Functions Functions are declared by first declaring the function type. This is the type of value to be returned by the function such as 'int' for an integer type function. If no value is to be returned the function type would be void. After type, declare the name given to the function and in parenthesis any parameters being passed to the function. type functionName(parameters) { statements; } int delayVal() { int v; // create temporary variable 'v' v = analogRead(pot); // read potentiometer value v /= 4; // converts 0-1023 to 0-255 return v; // return final value }

14 Suleyman Demirel University 201514 Flow control  If if(expression){ //if expression is true doSomething; }  if… else if(inputPin == HIGH){ doThingA; } else{ doThingB; }  For for (initialization; condition; expression){ doSomething; }  While while (expression){ doSomething; }  do… while do { doSomething; } while (someVariable ?? value); do{ // assign readSensors value to x x = readSensors(); delay (50); // pauses 50 milliseconds } while (x < 100); // loops if x is less than 100 while (someVariable < 200){ //if less than 200 doSomething; // executes enclosed statements someVariable++; // increments variable by 1 } for(j=0; j < 4; j++ ){ Serial.println(j); } if (inputPin < 500){ doThingA; } else if (inputPin >= 1000){ doThingB; } else{ doThingC; }

15 Suleyman Demirel University 201515 Comparing Character and Numeric Values

16 Suleyman Demirel University 201516 Comparing Strings char String1[ ] = "left"; char String2[ ] = "right"; if(strcmp(String1, String2) == 0) Serial.print("strings are equal) strcmp("left", "leftcenter") == 0) // this will evaluate to false strncmp("left", "leftcenter", 4) == 0) // this will evaluate to true

17 Suleyman Demirel University 201517 Logical and Bitwise operators Logical operatos Bitwise operators

18 Suleyman Demirel University 201518 Combining Operations and Assignment


Download ppt "Suleyman Demirel University 20151 CSS340 Microprocessor Systems – Lecture 1 Getting Started to Arduino."

Similar presentations


Ads by Google