Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <Wire.h>
- // Settings
- #define OVERTEMP 340
- // Pin assignments
- #define DPIN_RLED_SW 2
- #define DPIN_GLED 5
- #define DPIN_PWR 8
- #define DPIN_DRV_MODE 9
- #define DPIN_DRV_EN 10
- #define APIN_TEMP 0
- #define APIN_CHARGE 3
- boolean on = 0;
- unsigned long last_time = 0;
- float avg_loop_time = 0;
- int print_countdown = 50;
- void setup()
- {
- // We just powered on! That means either we got plugged
- // into USB, or the user is pressing the power button.
- pinMode(DPIN_PWR, INPUT);
- digitalWrite(DPIN_PWR, LOW);
- // Initialize GPIO
- pinMode(DPIN_RLED_SW, INPUT);
- pinMode(DPIN_GLED, OUTPUT);
- pinMode(DPIN_DRV_MODE, OUTPUT);
- pinMode(DPIN_DRV_EN, OUTPUT);
- digitalWrite(DPIN_DRV_MODE, LOW);
- digitalWrite(DPIN_DRV_EN, LOW);
- // Initialize serial busses
- Serial.begin(9600);
- Wire.begin();
- last_time = millis();
- Serial.println("Powered up!");
- }
- void loop()
- {
- unsigned long time = millis();
- //blink
- if (!on) {
- last_time = time;
- on = 1;
- analogRead(APIN_CHARGE);
- Serial.println("running");
- pinMode(DPIN_PWR, OUTPUT);
- digitalWrite(DPIN_PWR, HIGH);
- digitalWrite(DPIN_DRV_MODE, LOW);
- analogWrite(DPIN_DRV_EN, 64);
- }
- else {
- {// time passed *(int, so 2 is between 2 and 3)
- // Serial.println(time-last_time); // returns values from 2-5
- }
- { // avg time passed
- if(!print_countdown) {
- Serial.println(avg_loop_time); // stabilizes between 6 and 6.5 with print_countdown = 1, at 50, stabilizes at .1 or so.
- print_countdown = 50;
- }
- print_countdown --;
- avg_loop_time = (avg_loop_time*50.0 + (time-last_time))/51;
- }
- last_time=time;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment