Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #define BUTTON1 2
- #define BUTTON2 3
- #define BUTTON3 4
- #define BUTTON4 5
- #define LED1 7
- #define LED2 8
- #define LED3 9
- #define LED4 10
- #define LED5 11
- #define LED6 12
- #define LED7 13
- char aK1;
- char aK2;
- char aK3;
- char aK4;
- char L1;
- char L2;
- char L3;
- char L4;
- char L5;
- char L6;
- char L7;
- byte x[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
- byte y[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
- struct SerialV
- {
- char inputs;
- char outputs;
- };
- union SerialValues
- {
- SerialV s;
- uint16_t v;
- };
- void setup() {
- // put your setup code here, to run once:
- pinMode(BUTTON1, INPUT);
- pinMode(BUTTON2, INPUT);
- pinMode(BUTTON3, INPUT);
- pinMode(BUTTON4, INPUT);
- pinMode(LED1, OUTPUT);
- pinMode(LED2, OUTPUT);
- pinMode(LED3, OUTPUT);
- pinMode(LED4, OUTPUT);
- pinMode(LED5, OUTPUT);
- pinMode(LED6, OUTPUT);
- pinMode(LED7, OUTPUT);
- Wire.begin(8);
- Wire.onReceive(receiveEvent);
- Wire.onRequest(requestEvent);
- noInterrupts();
- TCCR1A = 0;
- TCCR1B = 0;
- TCNT1 = 65536 - 6249;
- TCCR1B |= (1 << CS12); // 256 prescaler
- TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
- interrupts();
- Serial.begin(115200);
- }
- void receiveEvent( int bytes ) {
- for(int i = 0; i < sizeof(y); i++){
- y[i] = Wire.read();
- }
- }
- void requestEvent()
- {
- Wire.write(x,14);
- }
- ISR(TIMER1_OVF_vect) // interrupt service routine
- {
- TCNT1 = 65536 - 6249; // preload timer
- implementacja();
- char inputs = 0;
- char outputs = 0;
- byte msg[2];
- outputs |= ((L7 && 1) << 6) | ((L6 && 1) << 5) | ((L5 && 1) << 4) | ((L4 && 1) << 3) | ((L3 && 1) << 2) |((L2 && 1) << 1) | (L1 && 1);
- inputs |= ((aK4 && 1) << 3) | ((aK3 && 1) << 2) | ((aK2 && 1) << 1) | (aK1 && 1);
- msg[0] = inputs;
- msg[1] = outputs;
- }
- void loop() {
- aK1 = digitalRead(BUTTON1);
- aK2 = digitalRead(BUTTON2);
- aK3 = digitalRead(BUTTON3);
- aK4 = digitalRead(BUTTON4);
- // put your main code here, to run repeatedly:
- digitalWrite(LED1, L1);
- digitalWrite(LED2, L2);
- digitalWrite(LED3, L3);
- digitalWrite(LED4, L4);
- digitalWrite(LED5, L5);
- digitalWrite(LED6, L6);
- digitalWrite(LED7, L7);
- }
- char T1x1 = 0, T1x2 = 0, T1x3 = 0, T2x1 = 0, T2x2 = 0, T2x3 = 0, T3x1 = 0, T3x2 = 0, T3x3 = 0, T4x1 = 0, T4x2 = 0, T4x3 = 0;
- char T1 = 0, T2 = 0, T3 = 0, T4 = 0;
- char Z1 = 0, Z2 = 0 , Z3 = 0, Z4 = 0, Z5 = 0, Z6 = 0;
- char G1 = 0, G2 = 0, G3 = 0, G4 = 0;
- char M1 = 0, M2 = 0, M3 = 0, M4 = 0;
- char stan1 = 1, stan2 = 1, stan3 = 1, stan4 = 1;
- char tim1 = 0, tim2 = 0, tim3 = 0, tim4 = 0;
- void implementacja()
- {
- //Przypisanie otrzymanych wartosci do poziomow wody
- T1x1 = y[0];
- T1x2 = y[1];
- T1x3 = y[2];
- T2x1 = y[3];
- T2x2 = y[4];
- T2x3 = y[5];
- T3x1 = y[6];
- T3x2 = y[7];
- T3x3 = y[8];
- T4x1 = y[9];
- T4x2 = y[10];
- T4x3 = y[11];
- //Przypisanie otrzymanych wartosci do poziomu termometrow
- T1 = y[12];
- T2 = y[13];
- T3 = y[14];
- T4 = y[15];
- //Zbiornik 1
- {
- }
- //Zbiornik 2
- {
- }
- //Zbiornik 3
- {
- }
- //Zbiornik 4
- {
- }
- //Przekazanie danych do obiektu
- x[0] = Z1;
- x[1] = Z2;
- x[2] = Z3;
- x[3] = Z4;
- x[4] = Z5;
- x[5] = Z6;
- x[6] = G1;
- x[7] = G2;
- x[8] = G3;
- x[9] = G4;
- x[10] = M1;
- x[11] = M2;
- x[12] = M3;
- x[13] = M4;
- //Obsluga timerow
- if(tim1) --tim1;
- if(tim2) --tim2;
- if(tim3) --tim3;
- if(tim4) --tim4;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement