Monday, February 26, 2007

why does this happen?

I am trying to get last week's assignment to work before going into this weeks
it seems to not like line 2 (int switchPin = 7;)
why do i get a:


error: redefinition of 'int switchPin' In function 'void setup()':
In function 'void loop()':


for this:
int ledPin = 13;
int switchPin = 7;
int pulsePin = 3;

int pulseLevel1 = 500;
int pulseLevel2 = 5000;
int pulseWidth = 1000;
int switchValue;

void setup() {
// make ledPin an output pin for mr. led
pinMode(ledPin, OUTPUT);
// make switchPin an input pin
pinMode(switchPin, INPUT);
//set internal pull up resistor
digitalWrite(switchPin, HIGH);
}

void loop() {

switchValue = digitalRead(switchPin);

if (switchValue == 0) { //i.e.: you've pushed the switch
//remember we're normally HIGH
// because of the internal pullup
pulseWidth = pulseLevel2;
} else {
pulseWidth = pulseLevel1;
}

//we actually do the pulsing here
digitalWrite(pulsePin, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(pulsePin, LOW);
delayMicroseconds(pulseWidth);
}



Thanks
k.

No comments: