Apresentação e dúvidas (pra variar lol)

8 views
Skip to first unread message

Antero Junior

unread,
May 8, 2014, 10:43:53 AM5/8/14
to arduino...@googlegroups.com
Bom dia pessoal! 
Comprei meu Arduino Uno R3 e algumas coisitas mais pra iniciar nesse mundo da automação.
Baixei a apostila (muito boa por sinal) do http://www.revistadoarduino.com.br e fiz um código que deveria ler o estado do led e mostrar a saída no LCD 16x2. 

int led = 13;
int ler = A0;

#include <LiquidCrystal.h>
#define Luz_Fundo  7

//cria um objeto tipo LiquidCrystal.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

  pinMode(led, OUTPUT);
  pinMode(ler, INPUT);

  // initialize serial communications:
  Serial.begin(9600);
  delay(100);
  lcd.begin(16, 2); // Iniciando o objeto "lcd" de 2 linhas e 16 colunas
  pinMode(Luz_Fundo,OUTPUT); //define o pino como saída
  digitalWrite(Luz_Fundo,HIGH); // Liga a luz do display.

}

void loop(){
  int ValorLed =  analogRead(ler);
  if (ValorLed > 0 ) {
    lcd.setCursor(0,0); // seta o cursor para: (coluna = 0, linha = 0)
    lcd.print("Led aceso ");
    Serial.print("Led aceso ");
    delay(1000);
  }
  else{
    lcd.setCursor(0,0); // seta o cursor para: (coluna = 0, linha = 0)
    Serial.print("Led apagado");
    delay(1000);
  }
  digitalWrite(led, HIGH);
  delay(1000);    
  digitalWrite(led,LOW);
  delay(1000);    
}  

Eu fiz a ligação do Led do pino 13 para o GND e pus um jumper que recebe o sinal do positivo do led e leva para a porta A0.
Mas não está funcionando... ¬¬ WHY? kkkkk



Antero Junior

unread,
May 8, 2014, 7:35:29 PM5/8/14
to arduino...@googlegroups.com
Fui forçado a adaptar o exemplo do push button. Tirei aquele loop e deu certo:

#include <LiquidCrystal.h> // declara a utilização da biblioteca LiquidCrystal
//cria um objeto tipo LiquidCrystal que chamei de "lcd" nos pinos citados:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define Luz_Fundo  7

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 8;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);  
  lcd.begin(16, 2); // Iniciando o objeto "lcd" de 2 linhas e 16 colunas
  pinMode(Luz_Fundo,OUTPUT); //define o pino como saída   
  digitalWrite(Luz_Fundo,HIGH); // Liga a luz do display.
  Serial.begin(9600);  
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {    
    // turn LED on:   
    digitalWrite(ledPin, HIGH);

    lcd.setCursor(0,0); // seta o cursor para: (coluna = 0, linha = 0)
    lcd.print("Aceso     ");
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin, HIGH);

    lcd.setCursor(0,0); // seta o cursor para: (coluna = 0, linha = 0)
    lcd.print("Apagado");
Reply all
Reply to author
Forward
0 new messages