mc.ino


1
#define F_CPU 8000000UL      //8Mhz ATtiny44
2
3
const int ledPin1 =  0;      // the number of the first LED pin 
4
const int ledPin2 =  1;      // the number of the second LED pin 
5
const int buttonPin = 2;     // the number of the pushbutton pin
6
const int raspiPwr = 3;      // the raspberipi powerswitch pin
7
const int raspi = 4;         // the raspberipi shutdown signal pin
8
const int testled =7;        // Only test led
9
10
int buttonState = 0;         // variable for reading the pushbutton status
11
int raspiPwrState = 0;       // variable for reading if raspi PWR is turned on or off
12
13
void setup() {
14
  // initialize the LED pins as an output:
15
  pinMode(ledPin1, OUTPUT);  
16
  pinMode(ledPin2, OUTPUT);  
17
  // initialize the pushbutton pin as an input:
18
  pinMode(buttonPin, INPUT);
19
  pinMode(raspi, OUTPUT);
20
  pinMode(raspiPwr, OUTPUT);
21
  pinMode(testled, OUTPUT);
22
  digitalWrite(ledPin1, HIGH);
23
  digitalWrite(buttonPin, HIGH);
24
  digitalWrite(raspi, HIGH);
25
  digitalWrite(raspiPwr, LOW);
26
  /*digitalWrite(testled, HIGH);
27
  delay(2000);
28
  digitalWrite(testled, LOW);*/  
29
}
30
31
void loop() {
32
 // read the state of the pushbutton and raspiPwr value:
33
  buttonState = digitalRead(buttonPin);
34
  raspiPwrState = digitalRead(raspiPwr);
35
  
36
  // check if the pushbutton is pressed.
37
  // if it is, the buttonState is LOW :
38
  if (buttonState == LOW) {
39
    delay(500);
40
  // turn raspi on:
41
  if (raspiPwrState == LOW) {
42
    digitalWrite(ledPin1, LOW);
43
    digitalWrite(ledPin2, HIGH);
44
    digitalWrite(raspi, HIGH);
45
    digitalWrite(raspiPwr, HIGH);
46
  }
47
  // turn Raspi off:
48
  if (raspiPwrState == HIGH) {
49
    digitalWrite(ledPin1, HIGH);
50
    digitalWrite(ledPin2, LOW);
51
    digitalWrite(raspi, LOW);
52
    delay(20000); // time to shutdown the raspberrypi
53
    digitalWrite(raspi, HIGH);
54
    digitalWrite(raspiPwr, LOW);
55
  } 
56
}  // buttonState
57
}  // loop