Last active
April 24, 2016 22:06
-
-
Save vinirodr/9ec2a8cfd6fa3923e53354f7761bf835 to your computer and use it in GitHub Desktop.
Assignment pcomp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Include header file | |
#include "pomodoro.h" | |
#include "Arduino.h" | |
Pomodoro::Pomodoro(int level) { | |
if (level == 0) { | |
for (int i = 2; i < 7; i++) { | |
// digitalWrite(i, LOW); | |
} | |
} | |
if (level == 0) { | |
_numberLeds = 5; | |
} | |
if (level > 0 && level < 200) { | |
_numberLeds = 4; | |
digitalWrite(2, HIGH); | |
} | |
if (level >= 200 && level < 400) { | |
_numberLeds = 3; | |
digitalWrite(3, HIGH); | |
} | |
if (level >= 400 && level < 600) { | |
_numberLeds = 2; | |
digitalWrite(4, HIGH); | |
} | |
if (level >= 600 && level < 800) { | |
_numberLeds = 1; | |
digitalWrite(5, HIGH); | |
} | |
if (level >= 800) { | |
_numberLeds = 0; | |
digitalWrite(6, HIGH); | |
} | |
_timer = _numberLeds * _timerParameter; | |
} | |
void Pomodoro::execute() { | |
Serial.println("Start Pomodoro!"); | |
// Print timer values | |
for (int i = 1; i <= _timer; i += 1000) { | |
Serial.println(i/1000); | |
delay(1000); | |
} | |
// Blink LEDs 10 times | |
for(int i = 0; i < 10; i++) { | |
for(int i = 2; i < 7; i++){ | |
digitalWrite(i, HIGH); | |
} | |
delay(150); | |
for(int i = 2; i < 7; i++){ | |
digitalWrite(i, LOW); | |
} | |
delay(150); | |
} | |
Serial.println("Finish!"); | |
// Turn on all LEDs | |
for(int i = 2; i < 7; i++){ | |
digitalWrite(i, HIGH); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef Pomodoro_h | |
#define Pomodoro_h | |
class Pomodoro { | |
public: | |
Pomodoro(int level); | |
void execute(); | |
private: | |
int _timer; | |
int _numberLeds; | |
const int _timerParameter = 10000; | |
}; | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Include Pomodoro library | |
#include "pomodoro.h" | |
// Pin potentiometer is attached | |
const int PIN_POT = A0; | |
const int PIN_SWITCH = 8; | |
// Pins LEDs are attached | |
const int LED_A = 2; | |
const int LED_B = 3; | |
const int LED_C = 4; | |
const int LED_D = 5; | |
const int LED_E = 6; | |
// Initialize variables | |
int start = 1; | |
int analogValue = 0; | |
void setup() { | |
// Set input potentiometer | |
pinMode(PIN_POT, INPUT); | |
// Set output LEDs | |
pinMode(LED_A, OUTPUT); | |
pinMode(LED_B, OUTPUT); | |
pinMode(LED_C, OUTPUT); | |
pinMode(LED_D, OUTPUT); | |
pinMode(LED_E, OUTPUT); | |
// Set serial to 9600 | |
Serial.begin(9600); | |
} | |
void loop() { | |
// Get analog value from potentiometer | |
analogValue = analogRead(PIN_POT); | |
Pomodoro myPomodoro(analogValue); | |
// Get digital value from switch | |
start = digitalRead(PIN_SWITCH); | |
// If start is pressed execute pomodoro | |
if (start == 1) { | |
myPomodoro.execute(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment