Code: |
char dummyvar; // to get Arduinoi IDE to include core headers properly #include <MsTimer2.h> const int inMultimedia = 13; const int inLight = 12; const int inBelt = 11; const int outBack = 10; const int outLight = 9; const int outBelt = 5; // Variables will change: int lightState = 0; int lastLightState = 0; // previous state of the light int lightCount = 0; unsigned long delai = 60000; unsigned long previousMillis = 0; int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by void setup() { // initialize the button pin as a input: pinMode(inMultimedia, INPUT); pinMode(inLight, INPUT); pinMode(inBelt, INPUT); // initialize the LED as an output: pinMode(outBack, OUTPUT); pinMode(outLight, OUTPUT); pinMode(outBelt, OUTPUT); // initialize serial communication: Serial.begin(9600); // Timer for led MsTimer2::set(10, flash); MsTimer2::start(); } void controlJoystick() { digitalWrite(outLight, HIGH); delay(50); digitalWrite(outLight, LOW); delay(50); digitalWrite(outLight, HIGH); delay(50); digitalWrite(outLight, LOW); delay(50); digitalWrite(outBack, HIGH); delay(50); digitalWrite(outBack, LOW); delay(50); } void flash() { //if (digitalRead(inCeint)) if (1) { // set the brightness of pin 9: analogWrite(outBelt, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } } } void loop() { // read the pushbutton input pin: if (digitalRead(inMultimedia)) { // GPS On unsigned long currentMillis = millis(); if (((unsigned long)(currentMillis - previousMillis) <= delai)) { // GPS is booting } else { previousMillis = currentMillis; // GPS ready if (lightCount != 0) { controlJoystick(); lightCount = 0; } } } else { // GPS down, do nothing } lightState = digitalRead(inLight); // compare the buttonState to its previous state if (lightState != lastLightState) { lightCount++; lightCount = lightCount % 2; } // save the current state as the last state, //for next time through the loop lastLightState = lightState; delay(100); } |