Pages: [1]   Go Down
Author Topic: Arduino 2 bottoni  (Read 667 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Salve sono nuovo oggi mi è arrivato arduino  smiley-razz.
Voglio far accendere il led corrispondente al bottone pigiato ma se qualsiasi dei 2 bottoni prema si accendono tutti e 2, come codice ho usato questo:
Code:

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // 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


const int buttonPin2 = 4;     // the number of the pushbutton pin
const int ledPin2 =  12;      // the number of the LED pin

// variables will change:
int buttonState2 = 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);    
  
  pinMode(ledPin2, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin2, INPUT);    
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  buttonState2 = digitalRead(buttonPin2);
  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {    
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
  
    if (buttonState2 == HIGH) {    
    // turn LED on:    
    digitalWrite(ledPin2, HIGH);  
  }
  else {
    // turn LED off:
    digitalWrite(ledPin2, LOW);
  }
}

Ma non funziona.
« Last Edit: December 10, 2010, 03:08:00 pm by lorigio » Logged

0
Online Online
Faraday Member
**
Karma: 45
Posts: 5783
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

il codice sembra buono, a livello hardware e' tutto connesso bene ? Hai messo le resistenze sui led ?
Logged

- [Guida] IDE - http://goo.gl/ln6glr
- [Lib] ST7032i LCD I2C - http://goo.gl/GNojT6
- [Lib] PCF8574+HD44780 LCD I2C - http://goo.gl/r7CstH

Viterbo
Offline Offline
Full Member
***
Karma: 0
Posts: 126
Non prendere la vita troppo sul serio. Tanto, comunque vada, non ne uscirai vivo.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Forse il problema sta nel collegamento del micro switch , hai messo la resistenza da 10k su di esso ? sei sicuro di prelevare l'input nel piedino giusto ?
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

risolto avevo sbagliato un collegamento  smiley-wink
Logged

Pages: [1]   Go Up
Jump to: