zbiorcze uzupełnienie mastera
This commit is contained in:
282
DiagAutomatedGearShifter/DiagAutomatedGearShifter.ino
Normal file
282
DiagAutomatedGearShifter/DiagAutomatedGearShifter.ino
Normal file
@@ -0,0 +1,282 @@
|
|||||||
|
//#include <avr/eeprom.h>
|
||||||
|
#include <Servo.h> // model servo: DS3218 PRO
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
#define Version "1.3"
|
||||||
|
//ostatnia zmiana: zmiana na PCB, dostrajanie
|
||||||
|
////2DO:
|
||||||
|
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 64
|
||||||
|
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||||
|
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
|
||||||
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
#define PinInSpeed 0 //on board: RXI
|
||||||
|
#define ServoSwitch 4 //on board: 4
|
||||||
|
#define ServoPin 8 //on board: 8
|
||||||
|
#define BrakingLight 9 //on board: 9 BrakingLight
|
||||||
|
#define PinLED 10 //on board: 10 ORANGE loop signal
|
||||||
|
#define Btn1 18 //on board: A0 Button0
|
||||||
|
#define Btn2 19 //on board: A1 Button1
|
||||||
|
|
||||||
|
#define ServoMaxAngle 130
|
||||||
|
#define MaxAngle 179
|
||||||
|
#define MinAngle 1
|
||||||
|
#define MaxGear 8
|
||||||
|
#define MinGear 1
|
||||||
|
#define WheelCircumference 2.130
|
||||||
|
#define MagnetsCnt 4
|
||||||
|
#define ms2kmh 3.6
|
||||||
|
#define Pi 3.1416
|
||||||
|
#define TimeToSleep 180000 //3 min
|
||||||
|
|
||||||
|
Servo myservo;
|
||||||
|
|
||||||
|
|
||||||
|
//SPEED
|
||||||
|
double speed = 0;
|
||||||
|
double speed_last = 0;
|
||||||
|
double speed_last_2 = 0;
|
||||||
|
double speed_last_3 = 0;
|
||||||
|
int speedTrend = 0;
|
||||||
|
double sigleTimeSpd = 0.0;
|
||||||
|
double sleepSpd = 0.0;
|
||||||
|
unsigned long millissSpd = millis();
|
||||||
|
unsigned long lastMillisSpd = millis();
|
||||||
|
unsigned long lastLastMillisSpd = millis();
|
||||||
|
unsigned long loopTime = millis();
|
||||||
|
//GEAR
|
||||||
|
int currentGear = 1;
|
||||||
|
int previousGear = 1;
|
||||||
|
int calculatedGear = 1;
|
||||||
|
//Przedziały dia biegów
|
||||||
|
float spdRange1and2 = 7.5;
|
||||||
|
float spdRange2and3 = 11.0;
|
||||||
|
float spdRange3and4 = 15.5;
|
||||||
|
float spdRange4and5 = 18.0;
|
||||||
|
float spdRange5and6 = 23.5;
|
||||||
|
float spdRange6and7 = 29.3;
|
||||||
|
float spdRange7and8 = 36.5;
|
||||||
|
double calcTimeDiff = 0.0;
|
||||||
|
double lastGearCalc = millis();
|
||||||
|
double changeDelayMs = 2000.0;
|
||||||
|
double accelerationShift = 1.0;
|
||||||
|
int displGear = 9 - currentGear;
|
||||||
|
float currentGearRangeLower = 0;
|
||||||
|
float currentGearRangeMiddle = 3.0;
|
||||||
|
float currentGearRangeUpper = 7.5;
|
||||||
|
//SERVO
|
||||||
|
int pos = 0;
|
||||||
|
int sleepMode = 0;
|
||||||
|
int servoCurrPos = ServoMaxAngle;
|
||||||
|
//GearBar
|
||||||
|
int gearBarHeight = 0;
|
||||||
|
int gearBarPosition = 0;
|
||||||
|
float speedForBar = 0;
|
||||||
|
//oth
|
||||||
|
int BrakingLightSwitch;
|
||||||
|
int ups = 0;
|
||||||
|
int downs = 0;
|
||||||
|
int run_hrs = 0;
|
||||||
|
int run_mins = 0;
|
||||||
|
//DST
|
||||||
|
int totalDist = 0;
|
||||||
|
int totalDistReaded = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
//SERVO
|
||||||
|
digitalWrite(ServoSwitch, HIGH);
|
||||||
|
myservo.attach(ServoPin); // attaches the servo on pin 4 to the servo object
|
||||||
|
setPosition(8);
|
||||||
|
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
//DIPLAY settings
|
||||||
|
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||||
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
|
for (;;); // Don't proceed, loop forever
|
||||||
|
}
|
||||||
|
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextColor(WHITE);
|
||||||
|
display.setRotation(0);
|
||||||
|
display.setTextSize(3);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("Version:");
|
||||||
|
display.setCursor(0, 25);
|
||||||
|
display.println(Version);
|
||||||
|
display.display();
|
||||||
|
delay(500);
|
||||||
|
//INPUT
|
||||||
|
pinMode(PinInSpeed, INPUT);
|
||||||
|
pinMode(Btn1, INPUT);
|
||||||
|
//OUTPUT
|
||||||
|
pinMode(PinLED, OUTPUT);
|
||||||
|
pinMode(BrakingLight, OUTPUT);
|
||||||
|
pinMode(ServoSwitch, OUTPUT);
|
||||||
|
|
||||||
|
//Interrupts
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PinInSpeed), diag, RISING);
|
||||||
|
|
||||||
|
// powolne ustawianie pozycji servo po włączeniu
|
||||||
|
// delay(750);
|
||||||
|
// setPosition(8);
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
delay(550);
|
||||||
|
setPosition(7);
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("wheelSize:");
|
||||||
|
display.setCursor(75, 0);
|
||||||
|
display.println(WheelCircumference);
|
||||||
|
display.setCursor(0, 16);
|
||||||
|
display.println("MagnetsCnt:");
|
||||||
|
display.setCursor(75, 16);
|
||||||
|
display.println(MagnetsCnt);
|
||||||
|
display.setCursor(0, 30);
|
||||||
|
display.println("TimeToSleep:");
|
||||||
|
display.setCursor(75, 30);
|
||||||
|
display.println(TimeToSleep);
|
||||||
|
display.setCursor(0, 45);
|
||||||
|
display.println("ServoMaxAgl:");
|
||||||
|
display.setCursor(75, 45);
|
||||||
|
display.println(ServoMaxAngle);
|
||||||
|
display.display();
|
||||||
|
//MEMORY
|
||||||
|
eeprom_read_block(&totalDistReaded, 0, 2);
|
||||||
|
totalDist = totalDistReaded;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(3);
|
||||||
|
speed = 17.7;//speed +1.0;
|
||||||
|
//################################################
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//duzy font
|
||||||
|
|
||||||
|
//SPEED_TREND
|
||||||
|
display.setCursor(100, 00);
|
||||||
|
if (speedTrend <= -1 ) {
|
||||||
|
display.write(31);
|
||||||
|
} else {
|
||||||
|
if (speedTrend >= 1) {
|
||||||
|
display.write(30);
|
||||||
|
} else {
|
||||||
|
display.println("-");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// digitalWrite(PinLED, HIGH);
|
||||||
|
// delay(500);
|
||||||
|
// digitalWrite(PinLED, LOW);
|
||||||
|
// delay(500);
|
||||||
|
|
||||||
|
|
||||||
|
display.display();
|
||||||
|
|
||||||
|
//wstrzymanie pętli by odczyty były co 0,5s
|
||||||
|
for (; (millis() - loopTime) < 100 ;) {
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
////przejście w tryb uśpienia za pomocą przycisku
|
||||||
|
if (digitalRead(Btn1) == HIGH) {
|
||||||
|
prepareTurnOff();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void diag(){
|
||||||
|
digitalWrite(PinLED, HIGH);
|
||||||
|
delay(200);
|
||||||
|
digitalWrite(PinLED, LOW);
|
||||||
|
delay(200);
|
||||||
|
digitalWrite(PinLED, HIGH);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPosition(int currentGear) {
|
||||||
|
pos = 180 - round((currentGear - 1) * (ServoMaxAngle / (MaxGear - 1) ));
|
||||||
|
if (pos >= 180) {
|
||||||
|
pos = MaxAngle;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos <= 0) {
|
||||||
|
pos = MinAngle;
|
||||||
|
}
|
||||||
|
if (sleepMode == 1 && speed > 0.0) {
|
||||||
|
digitalWrite(ServoSwitch, HIGH);
|
||||||
|
for (servoCurrPos = myservo.read(); servoCurrPos <= 180; servoCurrPos++) {
|
||||||
|
myservo.write(servoCurrPos);
|
||||||
|
delay(4);
|
||||||
|
}
|
||||||
|
sleepMode = 0;
|
||||||
|
}
|
||||||
|
myservo.write(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void prepareTurnOff() {
|
||||||
|
sleepMode = 1;
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("Przygotwywanie...");
|
||||||
|
display.display();
|
||||||
|
for (servoCurrPos = myservo.read(); servoCurrPos >= 60; servoCurrPos--) {
|
||||||
|
myservo.write(servoCurrPos);
|
||||||
|
delay(30);
|
||||||
|
}
|
||||||
|
for (; 1000 < (millis() - lastMillisSpd);) {
|
||||||
|
digitalWrite(ServoSwitch, LOW);
|
||||||
|
digitalWrite(ServoPin, LOW);
|
||||||
|
// myservo.detach(ServoPin);
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setCursor(0, 30);
|
||||||
|
display.println("Mozna teraz");
|
||||||
|
display.setCursor(0, 38);
|
||||||
|
display.println("bezpiecznie wylaczyc");
|
||||||
|
display.setCursor(0, 46);
|
||||||
|
display.println("komputer.");
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.write(31);
|
||||||
|
display.setCursor(5, 0);
|
||||||
|
display.println("+");
|
||||||
|
display.setCursor(10, 0);
|
||||||
|
display.write(30);
|
||||||
|
display.setCursor(20, 0);
|
||||||
|
display.println(downs + ups);
|
||||||
|
|
||||||
|
display.println("Spins: ");
|
||||||
|
display.setCursor(60, 0);
|
||||||
|
display.println(totalDist);;
|
||||||
|
display.setCursor(70, 0);
|
||||||
|
|
||||||
|
run_mins = floor((millis() / 1000) / 60);
|
||||||
|
run_hrs = floor(run_mins / 60);
|
||||||
|
run_mins = run_mins - (run_hrs * 60);
|
||||||
|
display.setCursor(64, 54);
|
||||||
|
display.println("T:");
|
||||||
|
display.setCursor(75, 54);
|
||||||
|
display.println(run_hrs);
|
||||||
|
display.setCursor(80, 54);
|
||||||
|
display.println(":");
|
||||||
|
display.setCursor(85, 54);
|
||||||
|
display.println(run_mins);
|
||||||
|
display.display();
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
155
INPUT_SINGAL_MAGNETIC/INPUT_SINGAL_MAGNETIC.ino
Normal file
155
INPUT_SINGAL_MAGNETIC/INPUT_SINGAL_MAGNETIC.ino
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
#include <Servo.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <time.h>
|
||||||
|
///include <avr/eeprom.h>
|
||||||
|
Adafruit_SSD1306 display(4);
|
||||||
|
|
||||||
|
#define PinInSpeed 0 //on board: RXI
|
||||||
|
#define PinInCadence 7 //on board: 7
|
||||||
|
#define PinInLED 9 //on board: 9
|
||||||
|
|
||||||
|
#define PinLedSpeed 5 //on board: 5 WHITE
|
||||||
|
#define PinLedCadence 6 //on board: 6 ORANGE DEEP SMALL
|
||||||
|
#define PinLED 10 //on board: 10 ORANGE BIG
|
||||||
|
#define PinBuzer 16 //on board: 16 Buzzer
|
||||||
|
|
||||||
|
#define ServoPin 4
|
||||||
|
#define ServoMaxAngle 180
|
||||||
|
#define MaxAngle 179
|
||||||
|
#define MinAngle 1
|
||||||
|
|
||||||
|
Servo myservo;
|
||||||
|
int pos = 0;
|
||||||
|
int spd_cnt = 0;
|
||||||
|
int spd_cnt_incr = 0;
|
||||||
|
int cad_cnt = 0;
|
||||||
|
int cad_cnt_incr = 0;
|
||||||
|
int i_loop = 0;
|
||||||
|
|
||||||
|
void calcSpeed() {
|
||||||
|
spd_cnt = spd_cnt + 1;
|
||||||
|
// digitalWrite(PinLedSpeed, HIGH);
|
||||||
|
// delay(50);
|
||||||
|
//digitalWrite(PinLedSpeed, LOW);
|
||||||
|
Serial.print("spd_cnt_metodaS: ");
|
||||||
|
Serial.print(spd_cnt);
|
||||||
|
Serial.println();
|
||||||
|
// if ( spd_cnt >= 2 )
|
||||||
|
// {
|
||||||
|
//
|
||||||
|
// spd_cnt_incr = spd_cnt_incr+1;
|
||||||
|
// spd_cnt = 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void calcCadence() {
|
||||||
|
cad_cnt = cad_cnt + 1;
|
||||||
|
digitalWrite(PinLedCadence, HIGH);
|
||||||
|
delay(50);
|
||||||
|
digitalWrite(PinLedCadence, LOW);
|
||||||
|
Serial.print("spd_cnt_metodaC: ");
|
||||||
|
Serial.print(cad_cnt);
|
||||||
|
Serial.println();
|
||||||
|
if ( cad_cnt >= 2 )
|
||||||
|
{
|
||||||
|
|
||||||
|
cad_cnt_incr = cad_cnt_incr+1;
|
||||||
|
cad_cnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
//DIPLAY settings
|
||||||
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextColor(WHITE);
|
||||||
|
display.setRotation(0);
|
||||||
|
display.setTextSize(1);
|
||||||
|
|
||||||
|
// display.invertDisplay(1);
|
||||||
|
// display.dim(1);
|
||||||
|
|
||||||
|
|
||||||
|
//INPUT
|
||||||
|
pinMode(PinInSpeed, INPUT);
|
||||||
|
pinMode(PinInCadence, INPUT);
|
||||||
|
pinMode(PinInLED, INPUT);
|
||||||
|
|
||||||
|
|
||||||
|
//OUTPUT
|
||||||
|
pinMode(PinLedSpeed, OUTPUT);
|
||||||
|
pinMode(PinLedCadence, OUTPUT);
|
||||||
|
pinMode(PinLED, OUTPUT);
|
||||||
|
pinMode(PinBuzer, OUTPUT);
|
||||||
|
|
||||||
|
|
||||||
|
//SERVO
|
||||||
|
myservo.attach(ServoPin); // attaches the servo on pin 4 to the servo object
|
||||||
|
|
||||||
|
|
||||||
|
//Interrupts
|
||||||
|
// delay(5000);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PinInSpeed), calcSpeed, FALLING);
|
||||||
|
//attachInterrupt(digitalPinToInterrupt(PinInCadence), calcCadence, FALLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("SPD_cnt: ");
|
||||||
|
|
||||||
|
display.setCursor(50, 0);
|
||||||
|
display.println(spd_cnt);
|
||||||
|
|
||||||
|
display.setCursor(0, 10);
|
||||||
|
display.println("SPD_inc: ");
|
||||||
|
|
||||||
|
display.setCursor(50, 10);
|
||||||
|
display.println(spd_cnt_incr);
|
||||||
|
|
||||||
|
display.display();
|
||||||
|
|
||||||
|
Serial.print("spd_cnt: ");
|
||||||
|
Serial.print(spd_cnt);
|
||||||
|
Serial.print("spd_cnt_incr: ");
|
||||||
|
Serial.print(spd_cnt_incr);
|
||||||
|
Serial.println();
|
||||||
|
//digitalWrite(PinLedCadence, HIGH);
|
||||||
|
//spd_cnt
|
||||||
|
//spd_cnt_incr
|
||||||
|
for (i_loop = 0; i_loop < spd_cnt_incr; i_loop++)
|
||||||
|
{
|
||||||
|
digitalWrite(PinLED, HIGH);
|
||||||
|
delay(100);
|
||||||
|
digitalWrite(PinLED, LOW);
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//for (i_loop = 0; i_loop < cad_cnt_incr; i_loop++)
|
||||||
|
//{
|
||||||
|
// digitalWrite(PinLED, HIGH);
|
||||||
|
// delay(100);
|
||||||
|
// digitalWrite(PinLED, LOW);
|
||||||
|
// delay(100);
|
||||||
|
//}
|
||||||
|
//cad_cnt_incr = 0;
|
||||||
|
|
||||||
|
|
||||||
|
spd_cnt_incr = 0;
|
||||||
|
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
// display.display();
|
||||||
|
display.clearDisplay();
|
||||||
|
}
|
||||||
134
SanityCheck/SanityCheck.ino
Normal file
134
SanityCheck/SanityCheck.ino
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
#include <Servo.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <time.h>
|
||||||
|
///include <avr/eeprom.h>
|
||||||
|
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 64
|
||||||
|
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||||
|
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
|
||||||
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
|
#define PinInSpeed 0 //on board: RXI
|
||||||
|
#define PinInCadence 7 //on board: 7
|
||||||
|
#define PinInLED 9 //on board: 9
|
||||||
|
|
||||||
|
#define PinLedSpeed 5 //on board: 5 WHITE
|
||||||
|
#define PinLedCadence 6 //on board: 6 ORANGE DEEP SMALL
|
||||||
|
#define PinLED 10 //on board: 10 ORANGE BIG
|
||||||
|
#define PinBuzer 16 //on board: 16 Buzzer
|
||||||
|
|
||||||
|
#define ServoPin 4
|
||||||
|
#define ServoMaxAngle 180
|
||||||
|
#define MaxAngle 179
|
||||||
|
#define MinAngle 1
|
||||||
|
|
||||||
|
Servo myservo;
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
void calcSpeed() {
|
||||||
|
digitalWrite(PinLedSpeed, HIGH);
|
||||||
|
delay(1000);
|
||||||
|
digitalWrite(PinLedSpeed, LOW);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void calcCadence() {
|
||||||
|
digitalWrite(PinLedCadence, HIGH);
|
||||||
|
delay(1000);
|
||||||
|
digitalWrite(PinLedCadence, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
//DIPLAY settings
|
||||||
|
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||||
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
|
for(;;); // Don't proceed, loop forever
|
||||||
|
}
|
||||||
|
display.display();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
|
||||||
|
//INPUT
|
||||||
|
pinMode(PinInSpeed, INPUT);
|
||||||
|
pinMode(PinInCadence, OUTPUT);
|
||||||
|
pinMode(PinInLED, INPUT);
|
||||||
|
|
||||||
|
//Interrupts
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PinInSpeed), calcSpeed, HIGH);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PinInCadence), calcCadence, RISING);
|
||||||
|
|
||||||
|
|
||||||
|
//OUTPUT
|
||||||
|
pinMode(PinLedSpeed, INPUT);
|
||||||
|
pinMode(PinLedCadence, OUTPUT);
|
||||||
|
pinMode(PinLED, OUTPUT);
|
||||||
|
pinMode(PinBuzer, OUTPUT);
|
||||||
|
|
||||||
|
|
||||||
|
//SERVO
|
||||||
|
myservo.attach(ServoPin); // attaches the servo on pin 4 to the servo object
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
|
||||||
|
display.println("LEDY ON 1s ");
|
||||||
|
digitalWrite(PinLedSpeed, HIGH);
|
||||||
|
digitalWrite(PinLedCadence, HIGH);
|
||||||
|
digitalWrite(PinLED, HIGH);
|
||||||
|
display.display();
|
||||||
|
delay(1000);
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("LEDY OFF 1s");
|
||||||
|
display.display();
|
||||||
|
digitalWrite(PinLedSpeed, LOW);
|
||||||
|
digitalWrite(PinLedCadence, LOW);
|
||||||
|
digitalWrite(PinLED, LOW);
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("BUZZER test");
|
||||||
|
display.display();
|
||||||
|
tone(PinBuzer, 500);
|
||||||
|
delay(500);
|
||||||
|
noTone(PinBuzer);
|
||||||
|
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("Servo 0");
|
||||||
|
display.display();
|
||||||
|
myservo.write(0);
|
||||||
|
delay(2000);
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("Servo 180");
|
||||||
|
display.display();
|
||||||
|
myservo.write(180);
|
||||||
|
delay(2000);
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("W8 4 input");
|
||||||
|
display.display();
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// display.display();
|
||||||
|
display.clearDisplay();
|
||||||
|
}
|
||||||
84
lampki_balkonowe_2_H_bridge/lampki_balkonowe_2_H_bridge.ino
Normal file
84
lampki_balkonowe_2_H_bridge/lampki_balkonowe_2_H_bridge.ino
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#include <Wire.h>
|
||||||
|
#include <BH1750.h>
|
||||||
|
#include <dht.h>
|
||||||
|
//#include <avr/sleep.h>
|
||||||
|
|
||||||
|
dht DHT;
|
||||||
|
//#define mosfetPin 9 //on board: 9
|
||||||
|
#define PinLED 10 //on board: 10 BLUE
|
||||||
|
#define PinLED2 14 //on board: 14 GRENN/BLUE
|
||||||
|
#define DHT11_PIN 15 //on board: 15 DHT11
|
||||||
|
#define PinLED3 16 //on board: 16 GRENN/BLUE
|
||||||
|
|
||||||
|
int delayStep = 20;
|
||||||
|
|
||||||
|
int brightness = 0;
|
||||||
|
int maxBrightness = 255;
|
||||||
|
|
||||||
|
int loops = 3;
|
||||||
|
int i_loops = 1;
|
||||||
|
int CurrentColor = PinLED2;
|
||||||
|
int CurrentColor2 = PinLED3;
|
||||||
|
|
||||||
|
BH1750 lightMeter;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
Wire.begin();
|
||||||
|
lightMeter.begin();
|
||||||
|
pinMode(PinLED, OUTPUT);
|
||||||
|
pinMode(PinLED2, OUTPUT);
|
||||||
|
pinMode(PinLED3, OUTPUT);
|
||||||
|
digitalWrite(CurrentColor2, LOW);
|
||||||
|
digitalWrite(CurrentColor, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Serrintln();
|
||||||
|
int chk = DHT.read11(DHT11_PIN);
|
||||||
|
uint16_t lux = lightMeter.readLightLevel();
|
||||||
|
Serial.print("Light: ");
|
||||||
|
Serial.print(lux);
|
||||||
|
Serial.println(" lx");
|
||||||
|
|
||||||
|
|
||||||
|
Serial.print("Temp: ");
|
||||||
|
Serial.print(DHT.temperature);
|
||||||
|
Serial.println();
|
||||||
|
Serial.print("Hum: ");
|
||||||
|
Serial.print(DHT.humidity);
|
||||||
|
Serial.println();
|
||||||
|
Serial.println();
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//###############blok docelowej pętli
|
||||||
|
if (lux < 10){
|
||||||
|
for (i_loops = 1; loops >= i_loops; i_loops++) {
|
||||||
|
|
||||||
|
//żółte
|
||||||
|
digitalWrite(CurrentColor, (maxBrightness*0,7));
|
||||||
|
analogWrite(CurrentColor2, LOW);
|
||||||
|
delay(10000);
|
||||||
|
//niebieskie
|
||||||
|
digitalWrite(CurrentColor, LOW);
|
||||||
|
analogWrite(CurrentColor2, (maxBrightness*0,95));
|
||||||
|
delay(10000);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
digitalWrite(CurrentColor2, LOW);
|
||||||
|
digitalWrite(CurrentColor, LOW);
|
||||||
|
digitalWrite(PinLED, HIGH);
|
||||||
|
delay(5);
|
||||||
|
digitalWrite(PinLED, LOW);
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
|
//###############blok docelowej pętli
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
99
temp_higr_dspl_lux/temp_higr_dspl_lux.ino
Normal file
99
temp_higr_dspl_lux/temp_higr_dspl_lux.ino
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#include <Wire.h>
|
||||||
|
#include <BH1750.h>
|
||||||
|
#include <dht.h>
|
||||||
|
#include <avr/sleep.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
dht DHT;
|
||||||
|
#define DHT11_PIN 15 //on board: 15 DHT11
|
||||||
|
#define VoltPin 18 //on board: 16 GRENN/BLUE
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 64
|
||||||
|
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||||
|
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
|
||||||
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
|
//VOLTAGE:
|
||||||
|
float referenceVoltage = 5.0;
|
||||||
|
int maxADCValue = 1023;
|
||||||
|
float voltageDividerRatio = 3.0;
|
||||||
|
int adcValue = 0;
|
||||||
|
float inputVoltage = 0.0;
|
||||||
|
float measuredVoltage = 0.0;
|
||||||
|
|
||||||
|
|
||||||
|
BH1750 lightMeter;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
Wire.begin();
|
||||||
|
lightMeter.begin();
|
||||||
|
pinMode(VoltPin, INPUT);
|
||||||
|
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextColor(WHITE);
|
||||||
|
display.setRotation(0);
|
||||||
|
display.setTextSize(3);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("TEST:");
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Serrintln();
|
||||||
|
int chk = DHT.read11(DHT11_PIN);
|
||||||
|
uint16_t lux = lightMeter.readLightLevel();
|
||||||
|
|
||||||
|
adcValue = analogRead(VoltPin);
|
||||||
|
measuredVoltage = (adcValue * referenceVoltage) / maxADCValue;
|
||||||
|
inputVoltage = measuredVoltage * voltageDividerRatio;
|
||||||
|
|
||||||
|
|
||||||
|
// Serial.print("Light: ");
|
||||||
|
// Serial.print(lux);
|
||||||
|
// Serial.println(" lx");
|
||||||
|
// Serial.print("Temp: ");
|
||||||
|
// Serial.print(DHT.temperature);
|
||||||
|
// Serial.println();
|
||||||
|
// Serial.print("Hum: ");
|
||||||
|
// Serial.print(DHT.humidity);
|
||||||
|
// Serial.println();
|
||||||
|
// Serial.print("Volt: ");
|
||||||
|
// Serial.print(inputVoltage );
|
||||||
|
// Serial.println();
|
||||||
|
// Serial.println();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("Temp:");
|
||||||
|
display.setCursor(30, 0);
|
||||||
|
display.println(DHT.temperature);
|
||||||
|
display.setCursor(64, 0);
|
||||||
|
display.println("Hum:");
|
||||||
|
display.setCursor(90, 0);
|
||||||
|
display.println(DHT.humidity);
|
||||||
|
display.setCursor(0, 32);
|
||||||
|
display.println("Volt:");
|
||||||
|
display.setCursor(30, 32);
|
||||||
|
display.println(inputVoltage);
|
||||||
|
display.setCursor(0, 50);
|
||||||
|
display.println("adcValue:");
|
||||||
|
display.setCursor(64, 50);
|
||||||
|
display.println(adcValue);
|
||||||
|
|
||||||
|
display.setCursor(64, 32);
|
||||||
|
display.println("Lux:");
|
||||||
|
display.setCursor(90, 32);
|
||||||
|
display.println(lux);
|
||||||
|
display.display();
|
||||||
|
delay(250);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user