Sketch: Blinking Led with Button/Millis Function

Blinking Led with Button

int ledPin = 13;
int inputPin1 = 3;
int inputPin2 = 2;
int i = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin1, INPUT);
pinMode(inputPin2, INPUT);
}

void loop(){

if (digitalRead(inputPin1) == LOW) {
digitalWrite(ledPin, LOW);
}
else if (digitalRead(inputPin2) == LOW) {
digitalWrite(ledPin, HIGH);

for (int i = 0; i < 10; i++) {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);

if (digitalRead(inputPin1) == LOW) {
digitalWrite(ledPin, LOW);
break;
}
}
}
}

Millis

unsigned long time;

void setup(){
Serial.begin(9600);
}
void loop(){
Serial.print(“Time: “);
time = millis();
//prints time since program started
Serial.println(time);
// wait a second so as not to send massive amounts of data
delay(1000);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s