Plus Five Iteration Loop
int x = 2;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("my number is ");
Serial.print(x);
Serial.print("\n"); //prints carriage return delay(200);
x+=5;
}
Plus One Iteration Loop
int x = 2;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("my number is ");
Serial.print(x);
Serial.print("\n"); //prints carriage return delay(200);
x++ ;
}
Minus Five Iteration Loop
int x = 2;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("my number is ");
Serial.print(x);
Serial.print("\n"); //prints carriage return delay(200);
x-=5 ;
}
LED Blinking Loop
void setup() {
Serial.begin(9600);
}
int pin_number = 6;
void loop() {
pinMode(pin_number, OUTPUT);
digitalWrite(pin_number, HIGH);
delay(200);
digitalWrite(pin_number, LOW);
delay(200);
}
Two LEDs Blinking Loop
void setup() {
Serial.begin(9600);
}
int pin_number = 6;
int pin_number2 = 5;
void loop() {
pinMode(pin_number, OUTPUT);
digitalWrite(pin_number, HIGH);
pinMode(pin_number2, OUTPUT);
digitalWrite(pin_number2, LOW);
delay(200);
digitalWrite(pin_number, LOW);
digitalWrite(pin_number2, HIGH);
delay(200);
}
Push Button LED Switch Loop
void setup() {
Serial.begin(9600);
}
int pin_number = 6;
void loop() {
pinMode(pin_number, OUTPUT);
digitalWrite(pin_number, HIGH);
}
Read Pin State Loop
void setup() {
Serial.begin(9600);
}
int buttonPin = 3;
int buttonState = digitalRead(buttonPin);
void loop() {
pinMode(buttonPin, INPUT);
int buttonState = digitalRead(buttonPin);
if
(buttonState == 1)
Serial.println("Button is not pressed");
else
Serial.println("Button is pressed");
}
Medical Device Reaction Time Loop
void setup() {
Serial.begin(9600);
}
int buttonPin = 3;
int buttonState = digitalRead(buttonPin);
int pin_number = 12;
void loop() {
pinMode(buttonPin, INPUT);
int buttonState = digitalRead(buttonPin);
pinMode(pin_number, OUTPUT);
digitalWrite(pin_number, HIGH);
if
(buttonState == 0)
Serial.println(millis());
}
Medical Device Timed Step Counter Loop
void setup() {
Serial.begin(9600);
}
int buttonPin = 3;
int buttonState = digitalRead(buttonPin);
int pin_number = 12;
int counter = 0;
void loop() {
pinMode(buttonPin, INPUT);
int buttonState = digitalRead(buttonPin);
int newstate = digitalRead(buttonPin);
if (buttonState != newstate)
buttonState = newstate;
if
(buttonState == 0)
++counter;
Serial.println(counter);
delay(200);
if ( (millis() >= 5000) && (counter <= 5) )
pinMode(pin_number, OUTPUT);
digitalWrite(pin_number, HIGH);
}
No comments:
Post a Comment