Re: Začátečník
Napsal: 07 úno 2017, 18:35
Tak arduino přežilo, LED svítí a pro příště se poučím. Tak díky za trpělivost.
Kód: Vybrat vše
//
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//nastavíme adresu a typ displeje
int i=0;
int sensorU1;
int sensorU2;
int sensorU3;
int sensorU4;
int sensorU5;
float sensorI1;
float U1;
float U2;
float U3;
float U4;
float U5;
float I1;
float Umax1;
float Umax2;
float Umax3;
float Umax4;
float Umax5;
float Imax1;
int stav = 1;
volatile int pryc = LOW;
LiquidCrystal_I2C lcd(0x27,16,2); // nastavení adresy (0x3F) je důležité!!!
void setup()
{
pinMode(4,INPUT_PULLUP);
pinMode(5,INPUT_PULLUP);
lcd.begin(); // initializace lcd
// Vypíšeme nějaké texty na jednotlivé řádky, adresace je od 0, ne od 1.
lcd.backlight();
lcd.setCursor ( 0, 0 );
lcd.print(" ARDUINO meric ");
lcd.setCursor ( 0, 1 );
lcd.print(" 5xU 1xI 1xrele ");
delay (2000);
lcd.clear();
lcd.backlight();
lcd.setCursor ( 0, 0 );
lcd.print(" KALIBRACE ");
delay(650);
lcd.setCursor ( 0, 1 );
for (i=0; i <17; i++){
lcd.print("X");
lcd.setCursor(i,1);
delay(90);}
delay(1000);
}
boolean ctiTL() { // cteni tlacitek a posuny v menu
int TL = 0;
delay(500);
do {
if (digitalRead(4) == LOW) TL += 1; // dalsi
if (digitalRead(5) == LOW) TL += 2; // enter
} while (TL == 0);
if (TL == 1) {
stav ++;
if (stav > 4) stav = 1;
// pip(10);
}
if (TL == 2) {
return true; // byl enter na zvoleny stav
} else {
return false; // nekorektni kombinace ignoruj
}
}
void loop()
{
lcd.clear();
lcd.print("Vyber funkce:");
lcd.setCursor(0, 1);
switch (stav) {
case 1: // Zmerit kapacitu
lcd.print("Aktualni hod. U");
if (ctiTL()) mereni();
break;
case 2: // Nabit
lcd.print("Max. hod. U a I");
if (ctiTL()) maxim();
break;
case 3: // Vybit
lcd.print("Min. hod. U a I");
if (ctiTL()) minim();
break;
case 4: // Formovat
lcd.print("Formovat (2,5 V)");
if (ctiTL()) formovat();
break;
}
}
void mereni(){
..........
.........
delay (1000);
if (digitalRead(4)==LOW) {return;}
//if (ctiTL()) return;
// do {} while (!ctiTL());
// return;
}
Kód: Vybrat vše
//------------------------------
void setup() {
Serial.begin(9600);
pinMode(4,INPUT_PULLUP);
}
//-------------------------------
void loop() {
//delay (300);
if (digitalRead(4)==LOW)
{
mereni();
}
digitalWrite(13,LOW);
}
//--------------------------------
void mereni(){
int count=0;
delay(300); // dulezity delay - aby vstupni LOW do mereni nebylo zaroven exitem mereni..
do {
count++;
Serial.println(count);
digitalWrite(13,HIGH);
//delay(300);
}
while (digitalRead(4)==HIGH);
delay(300);
}
Kód: Vybrat vše
byte sw=0;
byte interrupt0pin = 2;
int buttonState;
//------------------------------
void setup() {
pinMode(interrupt0pin, INPUT_PULLUP);
attachInterrupt(0, buttonUpdate, CHANGE); // calls buttonUpdate() tlacitko musi byt na 2 (INT0)
//Serial.begin(9600);
}
//-------------------------------
void loop() {
//Serial.println(sw);
if (sw %5 ==0) digitalWrite(13,HIGH);
else {digitalWrite(13,LOW);}
}
//------------------------------
void buttonUpdate(){
buttonState = digitalRead(2);
delay(50); // 50ms works for most switches - adjustable
if (buttonState)
{
sw++ ; // sw = sw + 1
}
}
//------------------------------