Ich versuche dies ( http://www.arduino.cc/en/Tutorial/Switch ) ohne externe Teile zu verwenden, da ich das Schaltflächenbeispiel von derselben Site mit diesem Code verwenden konnte: http://en.textsave .org/VjL ) mit meinem msp430g2553 mit Energia, aber es funktioniert nicht, irgendeine Hilfe?
const int buttonPin = PUSH2; // the number of the pushbutton pin
const int ledPin = GREEN_LED; // the number of the LED pin
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup(){
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);}
void loop(){
reading = digitalRead(ledPin);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH){
state = LOW;
}
else
state = HIGH;
time = millis(); }
digitalWrite(ledPin, state);
previous = reading;}
Äh, höchstwahrscheinlich verwenden Sie ein Launchpad der Version 1.5. Der externe Pullup-Pin für die p1.3-Taste ist nicht bestückt. Da es nicht besetzt ist, gibt es keine stationäre Zustandsänderung. Sie müssen den internen Pullup aktivieren.
Statt pinMode(buttonPin);
nutzenpinMode(buttonPin, INPUT_PULLUP);
Außerdem versuchen Sie, den falschen Pin zu lesen.
Statt reading = digitalRead(ledPin);
nutzenreading = digitalRead(buttonPin);
Schasam
Ignacio Vazquez-Abrams
DrRobotNinja
Cagurtay
Cagurtay
Cagurtay