Presentation is loading. Please wait.

Presentation is loading. Please wait.

Въведение в Arduino.

Similar presentations


Presentation on theme: "Въведение в Arduino."— Presentation transcript:

1 Въведение в Arduino

2 Какво е Ардуино? Open-source платформа с микроконтролер
Arduino IDE – програмна среда базирана на езикът C

3 Разлики със езикът C pinMode(10, OUTPUT); pinMode(11, INPUT);
Serial.begin(9600); Serial.end(); Serial.println(“message”); delay(time_ms);

4 Дигитал или аналог? digitalRead(10); digitalWrite(10,LOW);
analogRead(11); analogWrite(11,123);

5 Структура на кода Константи;
Void setup(){ - за изпълнение веднъж при стартиране }; Void loop(){ - безкраен цикъл за изпълнение };

6 Hello world, Arduino вариант
/*   Blink   Turns on an LED on for one second, then off for one second, repeatedly.     This example code is in the public domain.  */   // Pin 13 has an LED connected on most Arduino boards. // give it a name: int led = 13; // the setup routine runs once when you press reset: void setup() {                   // initialize the digital pin as an output.   pinMode(led, OUTPUT);      } // the loop routine runs over and over again forever: void loop() {   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)   delay(1000);               // wait for a second   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW   delay(1000);               // wait for a second }

7 pinMode, digitalWrite The command pinMode(pin, mode) is used to set the mode of Arduino pin – OUTPUT or INPUT. When it is OUTPUT it can be used to send information to another device, e.g. it can turn On or Off a LED. The command digitalWrite(pin, state) is used to send a state to output device, e.g. LED. You can turn on an LED using digitalWrite(pinNumber, HIGH) or turn it off with digitalWrite(pinNumber, LOW)

8 delay(milliseconds) The func delay(millis) is used to tell the processor to wait certain amount of time. delay(1000) tells the processor to wait exactly ms.

9 Task Attach an LED to pin 13 and then make it blink 3 times with intervals of 300 ms then 3 times with interval 900 ms and then again 3 times with interval 300 ms. The loop ends with 2 sec wait and then starts again.

10 Serial.print(char * message)
In order to debug arduino code you can use the command Serial.print in order to print messages from the arduino to the computer. In void setup() you must use Serial.begin(9600) in order to initialize the communication. When you want to print “a message” you just write in your code Serial.print(“a message”).

11 Fade in, Fade out int led = 9; // the pin that the LED is attached to void setup() { pinMode(led, OUTPUT); // declare pin 9 to be an output: } void loop() { // set the brightness of pin 9 from 0 to max: for(int brightness = 0; brightness <255; brightness ++) { analogWrite(led, brightness); delay(10); } // reverse: for(int brightness = 255; brightness <0; brightness --) { } }

12 Brightness control int potPin = 2; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int val = 0; // variable to store the value coming from the sensor void setup() { pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT } void loop() { val = analogRead(potPin); // read the value from the sensor analogWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255

13 Task Make the arduino send SOS signal (… ) and use a potentiometer to set the brightness.


Download ppt "Въведение в Arduino."

Similar presentations


Ads by Google