avatar
Untitled

Guest 542 18th Jul, 2023

                                           
                         //Diody RGB////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Arduino.h>        //Zaimplementowanie Bibliotek
#include "Mux.h"          //Zaimplementowanie Bibliotek
using namespace admux;        //Inicjalizacja
Mux mux(Pinset(8, 7, 6, 5));    //Stworzenie obiektu/zmiennej "mux" i przypisanie pinów sterujących do pinów: D2, D3, D4, D5

int RGB = 0;


//Serwo////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Servo.h>          //Zaimplementowanie Biblioteki
Servo servo;            //Stworzenie obiektu "servo"

int pos=0;                    //Zmienna "pos" przechowująca pozycję


//Wyswietlacz////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <TM1637Display.h>      //Zaimplementowanie Biblioteki

#define CLK 12           //Pin D4 jako CLK
#define DIO 11           //Pin D5 jako DIO
TM1637Display display(CLK, DIO);  //Konfiguracja wyświetlacza


//Potencjometr////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int wartosc_potencjometru_odczytana = 0;              //Zmienna do przechowywania danych odczytanych z pinu
unsigned int wartosc_potencjometru = 0;               //Zmienna tylko dodatnia to przechowywania przetowrzonych danych z potencjometru


//Przyciski////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int shot_1 = A1; 
int shot_2 = A2; 
int shot_3 = A3; 
int shot_4 = A4; 
int shot_5 = A5; 

int stan_1 = LOW;
int stan_2 = LOW;
int stan_3 = LOW;
int stan_4 = LOW;
int stan_5 = LOW;


//Pompa////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int pompa = 10;

void setup() {
  // put your setup code here, to run once:
mux.channel(RGB);  //RGB diody

servo.attach(9);          //Przypisanie serva do pinu D9
servo.write(0);

uint8_t clearMe[]={          //Tablica czyszczaca wyświetlacz
  0,0,0,0 
};
display.setBrightness(0x02);    //Ustawienie jasności w kodzie 16-tkowym
display.setSegments(clearMe);   //wyczyszczenie wyświetlacza


pinMode(shot_1, INPUT_PULLUP); //Przycisk jako wejście
pinMode(shot_2, INPUT_PULLUP); //Przycisk jako wejście
pinMode(shot_3, INPUT_PULLUP); //Przycisk jako wejście
pinMode(shot_4, INPUT_PULLUP); //Przycisk jako wejście
pinMode(shot_5, INPUT_PULLUP); //Przycisk jako wejście

pinMode(pompa, OUTPUT);
digitalWrite(pompa, HIGH);

rgb();
}

void loop() {
wartosc_potencjometru_odczytana = analogRead(A0);          //Odczytanie danych i Pinu A0 i przypisanie ich do zmiennej
wartosc_potencjometru = wartosc_potencjometru_odczytana * 0.0985; //Przemnożenie aby zmienić wartości z 0-1023 na 0-100

if(wartosc_potencjometru <=9){                    //Sprawdzenie czy wartość nie jest mniejsza od 4 jeśli tak to ustawienie wartości na 5
  wartosc_potencjometru = 10;
};

display.showNumberDec(wartosc_potencjometru,false, 4, 0);

  if(stan_1 == HIGH){
    mux.channel(2);
  }
  else{
    mux.channel(0);
  };
  
  if(stan_2 == HIGH){
    mux.channel(5);
  }
  else{
    mux.channel(0);
  };
  
  if(stan_3 == HIGH){
    mux.channel(8);
  }
  else{
    mux.channel(0);
  };
  
  if(stan_4 == HIGH){
    mux.channel(11);
  }
  else{
    mux.channel(0);
  };
  
  if(stan_5 == HIGH){
    mux.channel(14);
  }
  else{
    mux.channel(0);
  };


   if (digitalRead(shot_1) == HIGH ) { //Jeśli przycisk wciśnięty
  stan_1 = LOW;
  }if (digitalRead(shot_1) == LOW  && stan_1 == LOW ){
    nalej_1();
  };

   if (digitalRead(shot_2) == HIGH ) { //Jeśli przycisk wciśnięty
  stan_2 = LOW;
  }if (digitalRead(shot_2) == LOW  && stan_2 == LOW ){
    nalej_2();
  };
  
   if (digitalRead(shot_3) == HIGH ) { //Jeśli przycisk wciśnięty
  stan_3 = LOW;
  }if (digitalRead(shot_3) == LOW  && stan_3 == LOW ){
    nalej_3();
  };

   if (digitalRead(shot_4) == HIGH ) { //Jeśli przycisk wciśnięty
  stan_4 = LOW;
  }if (digitalRead(shot_4) == LOW  && stan_4 == LOW ){
    nalej_4();
  };

   if (digitalRead(shot_5) == HIGH ) { //Jeśli przycisk wciśnięty
  stan_5 = LOW;
  }if (digitalRead(shot_5) == LOW  && stan_5 == LOW ){
    nalej_5();
  };


}

void nalej_1()
{
    mux.channel(1);
    servo.write(180);
    delay(1250);
    mux.channel(3);
    digitalWrite(pompa, LOW);
    delay(wartosc_potencjometru*125);
    digitalWrite(pompa, HIGH);
    mux.channel(2);
    delay(50);
    servo.write(178);
    delay(250);
    servo.write(180);
    delay(250);
    servo.write(178);
    delay(250);
    servo.write(0);
    delay(2000);
    mux.channel(0);
    stan_1 = HIGH;
    
 
}

void nalej_2()
{
    mux.channel(4);
    servo.write(144);
    delay(1250);
    mux.channel(6);
    digitalWrite(pompa, LOW);
    delay(wartosc_potencjometru*125);
    digitalWrite(pompa, HIGH);
    mux.channel(5);
    delay(50);
    servo.write(146);
    delay(250);
    servo.write(142);
    delay(250);
    servo.write(146);
    delay(250);
    servo.write(0);
    delay(2000);
    mux.channel(0);
    stan_2 = HIGH;
 
}

void nalej_3()
{
    mux.channel(7);
    servo.write(108);
    delay(1250);
    mux.channel(9);
    digitalWrite(pompa, LOW);
    delay(wartosc_potencjometru*125);
    digitalWrite(pompa, HIGH);
    mux.channel(8);
    delay(50);
    servo.write(110);
    delay(250);
    servo.write(106);
    delay(250);
    servo.write(110);
    delay(250);
    servo.write(0);
    delay(2000);
    mux.channel(0);
    stan_3 = HIGH;
 
}

void nalej_4()
{
    mux.channel(10);
    servo.write(71);
    delay(1250);
    mux.channel(12);
    digitalWrite(pompa, LOW);
    delay(wartosc_potencjometru*125);
    digitalWrite(pompa, HIGH);
    mux.channel(11);
    delay(50);
    servo.write(73);
    delay(250);
    servo.write(69);
    delay(250);
    servo.write(73);
    delay(250);
    servo.write(0);
    delay(2000);
    mux.channel(0);
    stan_4 = HIGH;
 
}

void nalej_5()
{
    mux.channel(13);
    servo.write(34);
    delay(1250);
    mux.channel(15);
    digitalWrite(pompa, LOW);
    delay(wartosc_potencjometru*125);
    digitalWrite(pompa, HIGH);
    mux.channel(14);
        delay(50);
    servo.write(36);
    delay(250);
    servo.write(32);
    delay(250);
    servo.write(36);
    delay(250);
    servo.write(0);
    delay(2000);
    mux.channel(0);
    stan_5 = HIGH;
 
}

void rgb(){
int czas = 100;
  
  RGB = 1;
  mux.channel(RGB);
  delay(czas);
  for (int i=0; i<3; i++) {
  RGB = RGB+3;
  mux.channel(RGB);
  delay(czas);
}

  RGB = 13;
  mux.channel(RGB);
  delay(czas);
  for (int i=0; i<3; i++) {
  RGB = RGB-3;
  mux.channel(RGB);
  delay(czas);
}

  RGB = 2;
  mux.channel(RGB);
  delay(czas);
  for (int i=0; i<3; i++) {
  RGB = RGB+3;
  mux.channel(RGB);
  delay(czas);
}

  RGB = 14;
  mux.channel(RGB);
  delay(czas);
  for (int i=0; i<3; i++) {
  RGB = RGB-3;
  mux.channel(RGB);
  delay(czas);
}

  RGB = 3;
  mux.channel(RGB);
  delay(czas);
  for (int i=0; i<3; i++) {
  RGB = RGB+3;
  mux.channel(RGB);
  delay(czas);
}

  RGB = 15;
  mux.channel(RGB);
  delay(czas);
  for (int i=0; i<3; i++) {
  RGB = RGB-3;
  mux.channel(RGB);
  delay(czas);
}

  RGB = 1;
  mux.channel(RGB);
  delay(czas);
  for (int i=0; i<14; i++) {
  RGB = RGB+1;
  mux.channel(RGB);
  delay(czas);
}

  RGB = 1;
  mux.channel(RGB);
  delay(czas/2);
  for (int i=0; i<4; i++) {
  RGB = RGB+3;
  mux.channel(RGB);
  delay(czas/2);
}
delay(czas/2);
  RGB = 2;
  mux.channel(RGB);
  delay(czas/2);
  for (int i=0; i<4; i++) {
  RGB = RGB+3;
  mux.channel(RGB);
  delay(czas/2);
}
delay(czas/2);
  RGB = 3;
  mux.channel(RGB);
  delay(czas/2);
  for (int i=0; i<4; i++) {
  RGB = RGB+3;
  mux.channel(RGB);
  delay(czas/2);
}
delay(czas/2);

RGB = 0;
}
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes
Ta strona używa plików cookie w celu usprawnienia i ułatwienia dostępu do serwisu oraz prowadzenia danych statystycznych. Dalsze korzystanie z tej witryny oznacza akceptację tego stanu rzeczy.
Wykorzystywanie plików Cookie
Jak wyłączyć cookies?
ROZUMIEM