You are on page 1of 13

Controle USB

Utilizando Arduino com VB 2010

Plataforma Arduino

Plataforma Arduino
PC

USB

Conversor USB - Serial

Microcontrolador

Digital (0-13) Analgico(0-5)

Pinos 0 e 1

Arduino - Tipos

Arduino - Programao
Estruturas
Void Setup
Informa ao uC as entradas e sadas utilizadas

Void Loop
Programa de analise e escrita das
entradas/sadas

Arduino - Programao
Estruturas de Deciso
if (x > 120){
digitalWrite(LEDpin1, HIGH);
digitalWrite(LEDpin2, HIGH);

}
x == y (x is equal to y)
x != y (x is not equal to y)
x < y (x is less than y)
x > y (x is greater than y)
x <= y (x is less than or equal to y)
x >= y (x is greater than or equal to y)

Arduino - Programao
if (pinFiveInput < 500) {
// do Thing A

} else if (pinFiveInput >= 1000) {


// do Thing B

} else {
// do Thing C

Arduino - Programao
for (int i=0; i <= 255; i++){
analogWrite(PWMpin, i);
delay(10);

Arduino - Programao
switch (var) {
case 1:
//do something when var equals 1
break;

case 2:
//do something when var equals 2
break;

default:
// if nothing else matches, do the default
// default is optional

Arduino - Programao
var = 0;
while(var < 200){
// do something repetitive 200 times
var++;

Arduino - Programao
do {
delay(50);
// wait for sensors to stabilize
x = readSensors();
// check the sensors

} while (x < 100);

Arduino Sadas Digitais


int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT);// sets the digital pin as output

}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000);// waits for a second
digitalWrite(ledPin, LOW);// sets the LED off
delay(1000);// waits for a second

Arduino Sadas Digitais


int ledPin = 13; // LED connected to digital pin 13
int inPin = 7; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(inPin, INPUT); // sets the digital pin 7 as input

}
void loop()
{
val = digitalRead(inPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the button's value

You might also like