Social Icons

Jeremy Blum Projects - Arduino Parte [2]

Você que ainda não viu á parte 1 clique aqui!

Nesse Video trataremos sobre:

--> Saídas PWM e I/O
--> LED
--> Protoboard
--> Botões
--> ON/OFF Sem Ruídos







Código 1:

/*
Arduino Tutorials
Episode 2
Switch1 Program
Written by: Jeremy Blum
*/
int switchPin = 8;
int ledPin = 13;
void setup()
{
  pinMode(switchPin, INPUT);
  pinMode(ledPin, OUTPUT);
}
void loop()
{
  if (digitalRead(switchPin) == HIGH)
  {
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    digitalWrite(ledPin, LOW);
  }
}


----------------------------------------------------------------------
 Código 2

/*
Arduino Tutorials
Episode 2
Switch Program
Written by: Jeremy Blum
*/
int switchPin = 8;
int ledPin = 13;
boolean lastButton = LOW;
boolean ledOn = false;
void setup()
{
  pinMode(switchPin, INPUT);
  pinMode(ledPin, OUTPUT);
}
void loop()
{
  if (digitalRead(switchPin) == HIGH && lastButton == LOW)
  {
    ledOn = !ledOn;
    lastButton = HIGH;
  }
  else
  {
    //lastButton = LOW;
    lastButton = digitalRead(switchPin);
  }
 
  digitalWrite(ledPin, ledOn);
}

----------------------------------------------------

Código 3;

/*
Arduino Tutorials
Episode 2
Switch3 Program (debounced)
Written by: Jeremy Blum
*/
int switchPin = 8;
int ledPin = 13;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;
void setup()
{
  pinMode(switchPin, INPUT);
  pinMode(ledPin, OUTPUT);
}
boolean debounce(boolean last)
{
  boolean current = digitalRead(switchPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(switchPin);
  }
  return current;
}
void loop()
{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    ledOn = !ledOn;
  }
  lastButton = currentButton;
  digitalWrite(ledPin, ledOn);
}

----------------------------------------

Código 4;

/*
Arduino Tutorials
Episode 3
Switch4 Program (pwm)
Written by: Jeremy Blum
*/
int switchPin = 8;
int ledPin = 11;
boolean lastButton = LOW;
boolean currentButton = LOW;
int ledLevel = 0;

void setup()
{
  pinMode(switchPin, INPUT);
  pinMode(ledPin, OUTPUT);
}
boolean debounce(boolean last)
{
  boolean current = digitalRead(switchPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(switchPin);
  }
  return current;
}
void loop()
{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    ledLevel = ledLevel + 51;
  }
  lastButton = currentButton;
  if (ledLevel > 255) ledLevel = 0;
  analogWrite(ledPin, ledLevel);
}

Nenhum comentário:

Postar um comentário