natsonziom Napisano Luty 1, 2020 Udostępnij Napisano Luty 1, 2020 Cześć, hej 🙂 Czy jest tu jakaś dobra duszyczka, która chciałaby pomóc w napisaniu kodu dla arduino? Postaram się wszystko rozpisać co potrzebuję 🙂 Jestem w posiadaniu następujących elementów: Arduino UNO LED adresowane 12V 60d/m WS2811 Czujnik przepływu cieczy YF-S201 30l/m 3x wyświetlacz 8-segmentowy Chciałabym stworzyć instalacje działającą następująco - W zależności od przelanych litrów wody (zliczonych przez czujnik), Ledy gasiłyby się (tak wiem ze trzeba byłoby ustawić kilka trybów) oraz wyświetlacz (o początkowej liczbie 49l) zmniejsza się o liczbę wylanych litrów (również zliczonych przez czujnik) Potrzebuje połączyć trzy kody by ze sobą współgrały, wszystkie połączenia mam zrobione problemem zostaje sam program i jego połączenie 😞 Jeżeli chodzi o kod mam to zrobione bardzo chaotycznie (wybaczcie jestem jeszcze w tym wszystkim zielona) Prosiłabym o każdą wskazówkę i z góry bardzo dziękuję 🙂 KOD- CZUJNIK CIECZY /* Liquid flow rate sensor -DIYhacking.com Arvind Sanjeev Measure the liquid/water flow rate using this code. Connect Vcc and Gnd of sensor to arduino, and the signal line to arduino digital pin 2. */ byte statusLed = 13; byte sensorInterrupt = 0; // 0 = digital pin 2 byte sensorPin = 2; // The hall-effect flow sensor outputs approximately 4.5 pulses per second per // litre/minute of flow. float calibrationFactor = 4.5; volatile byte pulseCount; float flowRate; unsigned int flowMilliLitres; unsigned long totalMilliLitres; unsigned long oldTime; void setup() { // Initialize a serial connection for reporting values to the host Serial.begin(9600); // Set up the status LED line as an output pinMode(statusLed, OUTPUT); digitalWrite(statusLed, HIGH); // We have an active-low LED attached pinMode(sensorPin, INPUT); digitalWrite(sensorPin, HIGH); pulseCount = 0; flowRate = 0.0; flowMilliLitres = 0; totalMilliLitres = 0; oldTime = 0; // The Hall-effect sensor is connected to pin 2 which uses interrupt 0. // Configured to trigger on a FALLING state change (transition from HIGH // state to LOW state) attachInterrupt(sensorInterrupt, pulseCounter, FALLING); } /** * Main program loop */ void loop() { if((millis() - oldTime) > 1000) // Only process counters once per second { // Disable the interrupt while calculating flow rate and sending the value to // the host detachInterrupt(sensorInterrupt); // Because this loop may not complete in exactly 1 second intervals we calculate // the number of milliseconds that have passed since the last execution and use // that to scale the output. We also apply the calibrationFactor to scale the output // based on the number of pulses per second per units of measure (litres/minute in // this case) coming from the sensor. flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor; // Note the time this processing pass was executed. Note that because we've // disabled interrupts the millis() function won't actually be incrementing right // at this point, but it will still return the value it was set to just before // interrupts went away. oldTime = millis(); // Divide the flow rate in litres/minute by 60 to determine how many litres have // passed through the sensor in this 1 second interval, then multiply by 1000 to // convert to millilitres. flowMilliLitres = (flowRate / 60) * 1000; // Add the millilitres passed in this second to the cumulative total totalMilliLitres += flowMilliLitres; unsigned int frac; // Print the flow rate for this second in litres / minute Serial.print("Flow rate: "); Serial.print(int(flowRate)); // Print the integer part of the variable Serial.print("L/min"); Serial.print("\t"); // Print tab space // Print the cumulative total of litres flowed since starting Serial.print("Output Liquid Quantity: "); Serial.print(totalMilliLitres); Serial.println("mL"); Serial.print("\t"); // Print tab space Serial.print(totalMilliLitres/1000); Serial.print("L"); // Reset the pulse counter so we can start incrementing again pulseCount = 0; // Enable the interrupt again now that we've finished sending output attachInterrupt(sensorInterrupt, pulseCounter, FALLING); } } /* Insterrupt Service Routine */ void pulseCounter() { // Increment the pulse counter pulseCount++; } KOD LEDY #include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> #endif #define PIN 6 int nrLeds = 200; // Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) Adafruit_NeoPixel strip = Adafruit_NeoPixel(nrLeds, PIN, NEO_GRB + NEO_KHZ800); // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input // and minimize distance between Arduino and first pixel. Avoid connecting // on a live circuit...if you must, connect GND first. int state = 0; void setup() { // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket #if defined (__AVR_ATtiny85__) if (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif // End of trinket special code strip.begin(); strip.show(); // Initialize all pixels to 'off' } void loop() { // Some example procedures showing how to display to the pixels: //colorWipe(strip.Color(255, 0, 0), 50); // Red //colorWipe(strip.Color(0, 255, 0), 50); // Green // colorWipe(strip.Color(0, 0, 255), 50); // Blue //colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW // Send a theater pixel chase in... //theaterChase(strip.Color(127, 127, 127), 50); // White //theaterChase(strip.Color(127, 0, 0), 50); // Red //theaterChase(strip.Color(0, 0, 127), 50); // Blue //rainbow(20); //rainbowCycle(20); //theaterChaseRainbow(50); strip.clear(); switch(state) { case 0: for(uint16_t i=0; i<nrLeds; i++) { strip.setPixelColor(i, strip.Color(255, 255, 255)); strip.show(); } state = 1; break; case 1: for(uint16_t i=50; i<nrLeds-50; i++) { strip.setPixelColor(i, strip.Color(255, 255, 255)); strip.show(); } state = 2; break; case 2: for(uint16_t i=80; i<nrLeds-80; i++) { strip.setPixelColor(i, strip.Color(255, 255, 255)); strip.show(); } state = 0; break; } delay(5000); } // Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } } void rainbow(uint8_t wait) { uint16_t i, j; for(j=0; j<256; j++) { for(i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((i+j) & 255)); } strip.show(); delay(wait); } } // Slightly different, this makes the rainbow equally distributed throughout void rainbowCycle(uint8_t wait) { uint16_t i, j; for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel for(i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); } } //Theatre-style crawling lights. void theaterChase(uint32_t c, uint8_t wait) { for (int j=0; j<10; j++) { //do 10 cycles of chasing for (int q=0; q < 3; q++) { for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, c); //turn every third pixel on } strip.show(); delay(wait); for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } } } } //Theatre-style crawling lights with rainbow effect void theaterChaseRainbow(uint8_t wait) { for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel for (int q=0; q < 3; q++) { for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on } strip.show(); delay(wait); for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } } } } // Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } Z góry jeszcze raz dziękuję za wszystkie odpowiedzi Link do komentarza Share on other sites More sharing options...
Treker (Damian Szymański) Luty 1, 2020 Udostępnij Luty 1, 2020 @natsonziom jakiego rodzaju pomocy szukasz? Chcesz, aby ktoś to po prostu zrobił czy masz jakieś konkretne pytania i chcesz samodzielnie dojść do rozwiązania? Na czym konkretnie utknęłaś? Link do komentarza Share on other sites More sharing options...
natsonziom Luty 1, 2020 Autor tematu Udostępnij Luty 1, 2020 @Treker nie mam pojęcia jak połączyć to wszystko w jedno,czyli osobno kody działają ale nie współgrają ze sobą Link do komentarza Share on other sites More sharing options...
ethanak Luty 1, 2020 Udostępnij Luty 1, 2020 Bo nie masz "połączyć trzech kodów w jeden" tylko na ich podstawie napisać czwarty. Wyobraź sobie, że chcesz zrobić gołąbki z mięsem i ryżem. Masz przepis na świetne gołąbki z mięsem i na wspaniały ryż. Co wyjdzie z połączenia tych przepisów? Link do komentarza Share on other sites More sharing options...
Polecacz 101 Zarejestruj się lub zaloguj, aby ukryć tę reklamę. Zarejestruj się lub zaloguj, aby ukryć tę reklamę. Produkcja i montaż PCB - wybierz sprawdzone PCBWay! • Darmowe płytki dla studentów i projektów non-profit • Tylko 5$ za 10 prototypów PCB w 24 godziny • Usługa projektowania PCB na zlecenie • Montaż PCB od 30$ + bezpłatna dostawa i szablony • Darmowe narzędzie do podglądu plików Gerber Zobacz również » Film z fabryki PCBWay
Treker (Damian Szymański) Luty 1, 2020 Udostępnij Luty 1, 2020 26 minut temu, natsonziom napisał: @Treker nie mam pojęcia jak połączyć to wszystko w jedno,czyli osobno kody działają ale nie współgrają ze sobą No tak, to się domyśliłem - tylko, że jest to dość ogólny opis problemu. Zapytam więc jeszcze raz: chcesz, aby ktoś to po prostu zrobił czy masz jakieś konkretne techniczne pytania i chcesz samodzielnie dojść do rozwiązania? Utknęłaś na czymś konkretnym czy nie wiesz nawet jak ruszyć? Dopytuje, bo nie wiem czy liczysz na "gotowca", czy może jednak mamy zacząć tłumaczyć jak coś z tego "ulepić" 😉 Link do komentarza Share on other sites More sharing options...
natsonziom Luty 1, 2020 Autor tematu Udostępnij Luty 1, 2020 Jednak wolałabym sama do tego dojść, jednak nigdy wcześniej nie miałam z tym styczności stad moja osoba na tej grupie :) dziękuje za podpowiedz ze ma być to stworzone jako kod ‚4’ :) oczywiście mniej więcej sie tego domyslilam. Rozumiem ze wszystko uogólnilam, wiec może zacznę inaczej, czy mógłby ktoś wytłumaczyć jak mam stworzyć 4 kod bazując na trzech już napisanych kodach Link do komentarza Share on other sites More sharing options...
ethanak Luty 1, 2020 Udostępnij Luty 1, 2020 Spróbuj. Wyjdzie - dobrze. Nie wyjdzie - pokażemy co jest nie tak. Ale jeśli nie spróbujesz to na 100% nie wyjdzie. Każdy z nas kiedyś zaczynał, i w większości przypadków te pierwsze próby nadawały się do publikacji jako świetny dowcip na temat "jak nie należy programować". Link do komentarza Share on other sites More sharing options...
natsonziom Luty 1, 2020 Autor tematu Udostępnij Luty 1, 2020 11 minut temu, ethanak napisał: Spróbuj. Wyjdzie - dobrze. Nie wyjdzie - pokażemy co jest nie tak. Ale jeśli nie spróbujesz to na 100% nie wyjdzie. Każdy z nas kiedyś zaczynał, i w większości przypadków te pierwsze próby nadawały się do publikacji jako świetny dowcip na temat "jak nie należy programować". Dzięki 🙂 odezwę się jak już skleje co trzeba 🙂 Link do komentarza Share on other sites More sharing options...
ethanak Luty 1, 2020 Udostępnij Luty 1, 2020 Dam Ci jeszcze jedną wskazówkę: na podstawie danych z czujnika spróbuj napisać program określający, ile wody masz w zbiorniku. Niech po prostu wypisuje wyniki na serial. Jak to zrobisz - reszta będzie prosta (aż się zdziwisz, jak prosta). 1 Link do komentarza Share on other sites More sharing options...
natsonziom Luty 1, 2020 Autor tematu Udostępnij Luty 1, 2020 1 godzinę temu, ethanak napisał: Dam Ci jeszcze jedną wskazówkę: na podstawie danych z czujnika spróbuj napisać program określający, ile wody masz w zbiorniku. Niech po prostu wypisuje wyniki na serial. Jak to zrobisz - reszta będzie prosta (aż się zdziwisz, jak prosta). Ooo bardzo dziękuje 🙂 Link do komentarza Share on other sites More sharing options...
Pomocna odpowiedź
Bądź aktywny - zaloguj się lub utwórz konto!
Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony
Utwórz konto w ~20 sekund!
Zarejestruj nowe konto, to proste!
Zarejestruj się »Zaloguj się
Posiadasz własne konto? Użyj go!
Zaloguj się »