0% found this document useful (0 votes)
43 views3 pages

Code Research Arduino - 1

This Arduino code uses encoders and displays to track pusher activity over time. It initializes encoder and display libraries, defines pin connections, and sets up timers to monitor the encoders and update the displays. The main loop checks for encoder changes, increments counters, resets values, and prints outputs to track pusher 1 and 2 activity separately. It also reads the real-time clock to time-stamp events and stores values in EEPROM.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views3 pages

Code Research Arduino - 1

This Arduino code uses encoders and displays to track pusher activity over time. It initializes encoder and display libraries, defines pin connections, and sets up timers to monitor the encoders and update the displays. The main loop checks for encoder changes, increments counters, resets values, and prints outputs to track pusher 1 and 2 activity separately. It also reads the real-time clock to time-stamp events and stores values in EEPROM.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <Arduino.

h>
#include <BasicEncoder.h>
#include <TimerOne.h>
#include <GyverTM1637.h>
#include <uRTCLib.h>
#include <EEPROM.h>

BasicEncoder encoderA(2, 3);


BasicEncoder encoderB(5, 4);

uRTCLib rtc(0x68);
#define CLK1 7
#define DIO1 6
#define CLK2 9
#define DIO2 8
#define CLK3 11
#define DIO3 10
#define CLK4 13
#define DIO4 12
GyverTM1637 disp1(CLK1, DIO1); //Pusher_1_History
GyverTM1637 disp2(CLK2, DIO2); //Pusher_1_Realtime
GyverTM1637 disp3(CLK3, DIO3); //Pusher_2_History
GyverTM1637 disp4(CLK4, DIO4); //Pusher_2_Realtime

uint32_t Now1,Now2,limit1,limit2;
boolean flag1,flag2;
int encoder_a_change, encoder_b_change,encoder_b_count,encoder_a_count;
unsigned long prevTime = millis();
int minsA, secA, minsB, secB, mntA, dtkA, mntB, dtkB, P1, P2, Pusher = 0, loopin_1
= 0, loopin_2 = 0;
bool rst = false;
int state, lastState;

void timer_service() {
encoderA.service();
encoderB.service();
}

void setup() {
Serial.begin(9600);
URTCLIB_WIRE.begin();
Timer1.initialize(1000);
Timer1.attachInterrupt(timer_service);
disp1.clear();
disp2.clear();
disp3.clear();
disp4.clear();
disp1.brightness(1);
disp2.brightness(1);
disp3.brightness(1);
disp4.brightness(1);
disp1.point(1);
disp3.point(1);
disp2.point(1);
disp4.point(1);

rtc.set(0, 0, 0, 0, 0, 0, 0);
}
void loop() {
encoder_a_change = encoderA.get_change();
encoder_b_change = encoderB.get_change();
/////////////////////////////////
if (encoder_a_change){
if(encoderA.get_count() > 2){
Pusher = 1;
encoderB.reset();
P2 = 0;
loopin_1 = 0;
while(loopin_1 < 5){
if(encoderA.get_count() > P1){
Pusher = 1;
}
Serial.println("AAAAA");
Print();
P1 = encoderA.get_count();
/************/
if(encoderB.get_count() > 2){
loopin_1 = 10;
}
/************/
rtc.refresh();
uint32_t tmr1;
Now1 = millis();

while (millis () - Now1 < 1000) {


if (millis() - tmr1 > 500) { // every half second
tmr1 = millis();
flag1 = !flag1;
disp2.point(flag1);
disp4.point(flag1);
disp4.displayClock(rtc.minute(), rtc.second());
minsA = rtc.minute();
secA = rtc.second();
EEPROM.write(0, minsA);
EEPROM.write(1, secA);
}
}
disp2.point(1);
disp4.point(1);
/************/
}
Print();
P1 = encoderA.get_count();
}
Print();
P1 = encoderA.get_count();
}
/////////////////////////////////
disp2.displayClock(rtc.minute(), rtc.second());
rtc.set(0, 0, 0, 5, 24, 5, 22);
/////////////////////////////////
if (encoder_b_change){
if(encoderB.get_count() > 2){
Pusher = 2;
encoderA.reset();
P1 = 0;
loopin_2 = 0;
while(loopin_2 < 5){
if(encoderB.get_count() > P2){
Pusher = 2;
}
Serial.println("BBBBB");
Print();
P2 = encoderB.get_count();
/************/
if(encoderA.get_count() > 2){
loopin_2 = 10;
}
/************/
rtc.refresh();
uint32_t tmr1;
Now1 = millis();

while (millis () - Now1 < 1000) {


if (millis() - tmr1 > 500) { // every half second
tmr1 = millis();
flag1 = !flag1;
disp1.point(flag1);
disp4.point(flag1);
disp4.displayClock(rtc.minute(), rtc.second());
minsA = rtc.minute();
secA = rtc.second();
EEPROM.write(0, minsA);
EEPROM.write(1, secA);
}
}
disp1.point(1);
disp4.point(1);
/************/
}
}
Print();
P2 = encoderB.get_count();
}
disp1.displayClock(rtc.minute(), rtc.second());
rtc.set(0, 0, 0, 5, 24, 5, 22);

}
//***********************************//
void Print(){
Serial.print("Pusher >> ");
Serial.print(Pusher);
Serial.print(" A >> ");
Serial.print(encoderA.get_count());
Serial.print(" B >> ");
Serial.print(encoderB.get_count());
Serial.print(" ");
Serial.print(loopin_1);
Serial.println(loopin_2);
}
//***********************************//

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy