source: 2014/koodauskerho/38/JoonasM/Nopeuspeli.a/Nopeuspeli.a.ino @ 6277

Revision 5748, 1.5 KB checked in by jotapoti, 6 years ago (diff)
Line 
1  // Pin 13 has an LED connected on most Arduino boards.
2// give it a name:
3int led = 13;
4int led2 = 8;
5int led3 = 7;
6int led4 = 12;
7int pushbutton = 2;
8int ontime = 1500;
9int offtime = 1000;
10boolean state = false;
11boolean state2 = false;
12
13// the setup routine runs once when you press reset:
14void setup() {               
15   // initialize the digital pin as an output.
16   pinMode(led, OUTPUT); 
17   pinMode(led2, OUTPUT);
18   pinMode(led3, OUTPUT);
19   pinMode(led4, OUTPUT);
20   Serial.begin(9600);   
21   pinMode(pushbutton, INPUT);
22}
23 
24void jokin() {
25    digitalWrite(led, HIGH);
26    // tÀssÀ vÀlissÀ tÀytyy testata monta kertaa, kunnes sammuu
27    for (int i = 1; i<ontime ;i++) {
28       if (digitalRead(pushbutton) == 1 && state == false) {
29         if(ontime >= 200 ) {
30           ontime = ontime - 100;
31         }
32         state = true;
33         digitalWrite(led2, HIGH);
34      }
35      delay(1);
36    }
37    digitalWrite(led, LOW);
38    digitalWrite(led2, LOW);
39    for (int i = 1; i < offtime; i++) {
40      if (digitalRead(pushbutton) == 1 && state2 == false) {
41         if (ontime < 3000) {
42          ontime = ontime + 100;
43         }
44         state2 = true;
45         digitalWrite(led3, HIGH);
46      }
47      delay(1);
48    }
49    digitalWrite(led3, LOW);
50}
51
52// the loop routine runs over and over again forever:
53void loop() {
54
55  Serial.println(digitalRead(pushbutton));
56 
57  jokin();
58  state = false;
59  state2 = false;
60  delay(1);
61  if (ontime == 200) {
62      digitalWrite(led4, HIGH);
63      delay(3000);
64      digitalWrite(led4, LOW);
65      ontime = 1500;
66  }
67}
68
69
Note: See TracBrowser for help on using the repository browser.