Escolar Documentos
Profissional Documentos
Cultura Documentos
2 / 25
Board Selection
3 / 25
4 / 25
The Environment
SKETCH NAME
SERIAL MONITOR
5 / 25
SETUP:
The setup function is a default function type of the arduino environment It is mandatory to include this function. It runs only once at the start of the program. It is used for initialization of the different features of the controller, e.g. serial, pins direction etc.
LOOP:
The loop function is also a mandatory function. It contains the body of your code. It repeats itself over and over. (Analogous to a while(1) in the body of main() )
6 / 25
7 / 25
PINS
8 / 25
PINS
9 / 25
PINS
10 / 25
PINS
11 / 25
PINS
12 / 25
PINS
13 / 25
digitalwrite(pinnumber, state);
Int x = digitalRead(pinnumber);
14 / 25
15 / 25
Delay
Returns the number of milli seconds since the current program has been running Pauses the program for the amount of milliseconds mentioned. Pauses the program for the amount of microseconds mentioned.
delay(ms);
delaymicroseconds(us);
16 / 25
Delay
17 / 25
Analog Functions
Int x = analogread(pinanalog);
Pinanalog : Number assigned to the analog pins of the arduino This function uses the adc of the avr to convert the analog inputs. It returns a 10-bit(0 - 1023) integer value. This functions utilizes the pwm generation capability of the avr. Pinnumber is the number of the pin that can be used for pwm. Value ranges from 0 255. It is representation of the duty cycle of the output wave.
analogwrite(pinnumber, value);
18 / 25
Analog Functions
19 / 25
Analog Functions
20 / 25
External Interrupts
Interrupt : The number of the interrupt, i-e, 0,1, 2 etc Function : user defined to be called when the interrupt occurs Mode : The state at which interrupt should occur, e.g. LOW, CHANGE, RISING, FALLING
detachinterrupt(interrupt); The interrupts in the arduinomega2560 are on the following pins, with the interrupt number in the brackets:
2 (interrupt 4), 3 (interrupt 5), 18 (interrupt 3), 19 (interrupt 2), 20 (interrupt 1), and 21(interrupt 0).
21 / 25
External Interrupts
int pin = 13; volatile int state = LOW; void setup() { pinMode(pin, OUTPUT); attachInterrupt(0, blink, CHANGE); } void loop() { digitalWrite(pin, state); } void blink() { state = !state; }
@ Dr Javaid, M.H Fidai
22 / 25
Serial
Serial.begin(baudrate);
Initializes the serial hardware for communication at the baud rate mentioned
Transmits the data. Serial.println adds a carriage return (\r\n) to the data. Reads the data received. Returns a value that indicates how many unread bytes are there.
Int Serial.read();
Int serial.available();
Serial.flush();
23 / 25
Serial
24 / 25