skorek1989 Październik 28, 2019 Autor tematu Udostępnij Październik 28, 2019 (edytowany) Super! Działa teraz podepnę pod arduino i przetestuje. Działa w sensie że jak dotykam + to przekaźnik się otwiera a jak dotknę - to się zamyka.... Edytowano Październik 28, 2019 przez skorek1989 Cytuj Link do komentarza Share on other sites More sharing options...
RFM Październik 28, 2019 Udostępnij Październik 28, 2019 38 minut temu, atMegaTona napisał: Po co ta dioda Zabezpiecza przed indukowaniem się wysokiego napięcia w chwili rozłączenia tranzystora (tak działają przetwornice step-up), które może uszkodzić tranzystor. 1 Cytuj Link do komentarza Share on other sites More sharing options...
Treker (Damian Szymański) Październik 28, 2019 Udostępnij Październik 28, 2019 @RFM to pytanie dotyczyło chyba innej diody, bo tam na schemacie była zaznaczona jeszcze jedna - wpięta szeregowo 😉 Cytuj Link do komentarza Share on other sites More sharing options...
Anonim Październik 28, 2019 Udostępnij Październik 28, 2019 @RFM chodziło o tę o której @Treker napisał. Ta przy przekaźniku to oczywista oczywistość. Kiedyś się zastanawiałem dlaczego producenci tych przekaźników nie montują tych diod fabrycznie i nie wiem do tej pory. Pewnie się już nie dowiem bo przekaźniki powoli odchodzą do historii. Cytuj 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
RFM Październik 28, 2019 Udostępnij Październik 28, 2019 4 minuty temu, atMegaTona napisał: Kiedyś się zastanawiałem dlaczego producenci tych przekaźników nie montują tych diod fabrycznie Bo to podwyższa cena 🙂 Tak naprawdę, to taka dioda może być problemem, bo narzuca konkretne połączenia na PCB. Gdy PK sterujesz z innego PK, przycisku, to jest zbedna a utrudnia prowadzenie ścieżek. Wiele układów ma wbudowane diody (np ULN200x 280x). 1 Cytuj Link do komentarza Share on other sites More sharing options...
skorek1989 Październik 28, 2019 Autor tematu Udostępnij Październik 28, 2019 Niestety po podpięciu pod arduino nie działa. Przy podłączeniu wedle schematu 1 gdy dotykam A5 to przekaźnik zaskakuje ale jak czas dojdzie do 0 i pokazuje napis WINER to przekaźnik nie reaguje. W przypadku schematu 2 gdy podłączam się do arduino to przekaźnik działa ale jak podepnę się pod A5 i czas dojdzie do końca to nadal nic się nie dzieje. Cytuj Link do komentarza Share on other sites More sharing options...
RFM Październik 28, 2019 Udostępnij Październik 28, 2019 12 minut temu, skorek1989 napisał: przekaźnik nie reaguje Sprawdź poziom logiczny na A5. Cytuj Link do komentarza Share on other sites More sharing options...
skorek1989 Październik 28, 2019 Autor tematu Udostępnij Październik 28, 2019 Jak bym mógł prosić o rozwinięcie poziom logiczny A5. Przyznam szczerze że pierwszy raz w życiu robie coś w C i na arduino. Cytuj Link do komentarza Share on other sites More sharing options...
Anonim Październik 28, 2019 Udostępnij Październik 28, 2019 Załaduj sobie dla próby blink i zmień w nim tylko pin na A5 i sprawdź czy przekaźnik cyka. Jak wgrać blinka znajdziesz w necie na 100% Cytuj Link do komentarza Share on other sites More sharing options...
RFM Październik 28, 2019 Udostępnij Październik 28, 2019 Powrócę do tematu diody zabezpieczającej na przekaźniku. Niby mogło by jej nie być bo tranzystor ma pasożytnicza diodę. Wydaje się, ze nie pełni ona w tej sytuacji żadnej roli bo jest włączona zaporowo ale nie wszyscy wiedzą, że ta dioda to dioda Zenera o napięciu trochę wyższym niż maksymalne dopuszczalne napięcie Uds. W pewnych sytuacjach, dioda ta wystarczy aby ochronić tranzystor przed zniszczeniem ale bezpieczniej dać dodatkowa na indukcyjności. Cytuj Link do komentarza Share on other sites More sharing options...
skorek1989 Październik 29, 2019 Autor tematu Udostępnij Październik 29, 2019 @atMegaTona dzięki jutro sprawdzę czy zadziała i powrócę do tematu. Cytuj Link do komentarza Share on other sites More sharing options...
skorek1989 Październik 30, 2019 Autor tematu Udostępnij Październik 30, 2019 Dnia 28.10.2019 o 21:18, atMegaTona napisał: Załaduj sobie dla próby blink i zmień w nim tylko pin na A5 i sprawdź czy przekaźnik cyka. Jak wgrać blinka znajdziesz w necie na 100% Witam po krótkiej przerwie. Zrobiłem jak pisałeś załadowałem blinka i działa co sekundę przełączało przekaźnik. Cytuj Link do komentarza Share on other sites More sharing options...
skorek1989 Październik 31, 2019 Autor tematu Udostępnij Październik 31, 2019 @atMegaTona jakiś pomysł? Cytuj Link do komentarza Share on other sites More sharing options...
Treker (Damian Szymański) Październik 31, 2019 Udostępnij Październik 31, 2019 @skorek1989 pokaż dla pewności aktualną wersję Twojego programu i schematu 😉 Cytuj Link do komentarza Share on other sites More sharing options...
skorek1989 Listopad 4, 2019 Autor tematu Udostępnij Listopad 4, 2019 @Treker Cześć, poniżej aktualny kod oraz schemat. /* BOOMBA ASG */ #include <LiquidCrystal.h> #include <EEPROM.h> //defining seconds count #define SEC (60 +(millis() / 1000)) //define keypad buttons #define btnRIGHT 0 #define btnUP 1 #define btnDOWN 2 #define btnLEFT 3 #define btnSELECT 4 #define btnNONE 5 //constants const int buttonOrange = A1; const int buttonRed = A3; const int pinBuzzer = A5; const int analogPin = A0; //Variables for keypad and menu int lcd_key = 0; int adc_key_in = 0; int countMenu = 0; int blinkTime; int initBlinkTime; int blinkDelay = 500; bool exitMenu = true; bool sidePlayer = true; bool blinkState = true; //Variables for seconds count int cTemp = 0; int cSecOrange = 0; int cSecRed = 0; //Increment variable int setInc; //Variables to Orange timer int setSecOrange; int horOrange; int minOrange; int secOrange; //Variables to red timer int setSecRed; int horRed; int minRed; int secRed; //LCD setup const int rs = 8, e = 10, d4 = 4, d5 = 5, d6 = 6, d7 = 7, d9 = 9 ; LiquidCrystal lcd(8, 1, 9, 4, 5, 6, 7); //fix bounce of keys void debounceKey() { while (adc_key_in < 1000) { adc_key_in = analogRead(analogPin); } } //keypad code by: //https://www.dfrobot.com/wiki/index.php/Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009) //read keypad buttons int read_LCD_buttons() { adc_key_in = analogRead(analogPin); // read the value from the sensor // my buttons when read are centered at these valies: 0, 144, 329, 504, 741 // we add approx 50 to those values and check to see if we are close if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result // For V1.1 us this threshold /*if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 250) return btnUP; if (adc_key_in < 450) return btnDOWN; if (adc_key_in < 650) return btnLEFT; if (adc_key_in < 850) return btnSELECT; */ // For V1.0 comment the other threshold and use the one below: if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 195) return btnUP; if (adc_key_in < 380) return btnDOWN; if (adc_key_in < 555) return btnLEFT; if (adc_key_in < 790) return btnSELECT; return btnNONE; // when all others fail, return this... } //set up menu void menuSetUp() { lcd_key = read_LCD_buttons(); // read the buttons switch (lcd_key) // depending on which button was pushed, we perform an action { case btnRIGHT: { countMenu++; if (countMenu > 4) countMenu = 0; debounceKey(); break; } case btnLEFT: { countMenu--; if (countMenu < 0) countMenu = 4; debounceKey(); break; } case btnUP: { if (countMenu == 0) { //increase hour horOrange++; if (horOrange > 9) horOrange = 0; debounceKey(); } else if (countMenu == 1) { //increase minutes minOrange++; if (minOrange > 59) minOrange = 0; debounceKey(); } else if (countMenu == 2) { //increase seconds secOrange++; if (secOrange > 59) secOrange = 0; debounceKey(); } else if (countMenu == 3) { //increase increment setInc++; if (setInc > 99) setInc = 0; debounceKey(); } else { //change OR to RO sidePlayer ^= 1; debounceKey(); } break; } case btnDOWN: { if (countMenu == 0) { //decrease hour horOrange--; if (horOrange < 0) horOrange = 9; debounceKey(); } else if (countMenu == 1) { //decrease minutes minOrange--; if (minOrange < 0) minOrange = 59; debounceKey(); } else if (countMenu == 2) { //decrease seconds secOrange--; if (secOrange < 0) secOrange = 59; debounceKey(); } else if (countMenu == 3) { //decrease increment setInc--; if (setInc < 0) setInc = 99; debounceKey(); } else { //change OR to RO sidePlayer ^= 1; debounceKey(); } break; } case btnSELECT: //exit set up menu { exitMenu = 0; break; } case btnNONE: { break; } } } //printing orange values to LCD and print timer to set up menu void printTimerOrange() { //used to timer blink blinkTime = millis() - blinkDelay; //printing hour blinking //used only in set up if (exitMenu == 1 && countMenu == 0) { if (blinkTime >= initBlinkTime && blinkState == 1) { lcd.setCursor(0, 1); lcd.print(" "); blinkState = 0; initBlinkTime = millis(); } if (blinkTime >= initBlinkTime && blinkState == 0) { lcd.setCursor(0, 1); lcd.print(horOrange); blinkState = 1; initBlinkTime = millis(); } } //printing hour withouy blink else { lcd.setCursor(0, 1); lcd.print(horOrange); } lcd.setCursor(1, 1); lcd.print(":"); //printing minutes blinking //used only in set up if (exitMenu == 1 && countMenu == 1) { if (blinkTime >= initBlinkTime && blinkState == 1) { lcd.setCursor(2, 1); lcd.print(" "); blinkState = 0; initBlinkTime = millis(); } if (blinkTime >= initBlinkTime && blinkState == 0) { //this fix the print value below 10 moving the cursor one point and put 0 to left if ((minOrange < 10) && (minOrange >= 0)) { lcd.setCursor(2, 1); lcd.print(0); lcd.setCursor(3, 1); lcd.print(minOrange); } else { lcd.setCursor(2, 1); lcd.print(minOrange); } blinkState = 1; initBlinkTime = millis(); } } //printing minutes without blink else { //this fix the print value below 10 moving the cursor one point and put 0 to left if ((minOrange < 10) && (minOrange >= 0)) { lcd.setCursor(2, 1); lcd.print(0); lcd.setCursor(3, 1); lcd.print(minOrange); } else { lcd.setCursor(2, 1); lcd.print(minOrange); } } lcd.setCursor(4, 1); lcd.print(":"); //print seconds blinking //used only in set up if (exitMenu == 1 && countMenu == 2) { if (blinkTime >= initBlinkTime && blinkState == 1) { lcd.setCursor(5, 1); lcd.print(" "); blinkState = 0; initBlinkTime = millis(); } if (blinkTime >= initBlinkTime && blinkState == 0) { //this fix the print value below 10 moving the cursor one point and put 0 to left if ((secOrange < 10) && (secOrange >= 0)) { lcd.setCursor(5, 1); lcd.print(0); lcd.setCursor(6, 1); lcd.print(secOrange); } else { lcd.setCursor(5, 1); lcd.print(secOrange); } blinkState = 1; initBlinkTime = millis(); } } //print seconds without blink else { //this fix the print value below 10 moving the cursor one point and put 0 to left if ((secOrange < 10) && (secOrange >= 0)) { lcd.setCursor(5, 1); lcd.print(0); lcd.setCursor(6, 1); lcd.print(secOrange); } else { lcd.setCursor(5, 1); lcd.print(secOrange); } } } //printing red values to LCD void printTimerRed() { //printing hour lcd.setCursor(9, 1); lcd.print(horRed); lcd.setCursor(10, 1); lcd.print(":"); //printing minutes //this fix the print value below 10 moving the cursor one point and put 0 to left if ((minRed < 10) && (minRed >= 0)) { lcd.setCursor(11, 1); lcd.print(0); lcd.setCursor(12, 1); lcd.print(minRed); } else { lcd.setCursor(11, 1); lcd.print(minRed); } lcd.setCursor(13, 1); lcd.print(":"); //print seconds //this fix the print value below 10 moving the cursor one point and put 0 to left if ((secRed < 10) && (secRed >= 0)) { lcd.setCursor(14, 1); lcd.print(0); lcd.setCursor(15, 1); lcd.print(secRed); } else { lcd.setCursor(14, 1); lcd.print(secRed); } } //print menu set up void printMenu() { lcd.setCursor(0, 0); lcd.print("SET UP O/ KEYPAD"); lcd.setCursor(8, 1); lcd.print("Inc"); //used to timer blink blinkTime = millis() - blinkDelay; //print increment value to set up if (countMenu == 3) { //print increment value blinking if (blinkTime >= initBlinkTime && blinkState == 1) { lcd.setCursor(11, 1); lcd.print(" "); blinkState = 0; initBlinkTime = millis(); } if (blinkTime >= initBlinkTime && blinkState == 0) { //this fix the print value below 10 moving the cursor one point and put 0 to left if ((setInc < 10) && (setInc >= 0)) { lcd.setCursor(11, 1); lcd.print(0); lcd.setCursor(12, 1); lcd.print(setInc); } else { lcd.setCursor(11, 1); lcd.print(setInc); } blinkState = 1; initBlinkTime = millis(); } } //print increment value without blink else { //this fix the print value below 10 moving the cursor one point and put 0 to left if ((setInc < 10) && (setInc >= 0)) { lcd.setCursor(11, 1); lcd.print(0); lcd.setCursor(12, 1); lcd.print(setInc); } else { lcd.setCursor(11, 1); lcd.print(setInc); } } //print side player (OR or RO) blinking if (exitMenu == 1 && countMenu == 4) { if (blinkTime >= initBlinkTime && blinkState == 1) { lcd.setCursor(14, 1); lcd.print(" "); blinkState = 0; initBlinkTime = millis(); } if (blinkTime >= initBlinkTime && blinkState == 0) { if (sidePlayer == 1) { lcd.setCursor(14, 1); lcd.print("OR"); } else { lcd.setCursor(14, 1); lcd.print("RO"); } blinkState = 1; initBlinkTime = millis(); } } //print side player (OR or RO) without blink else { if (sidePlayer == 1) { lcd.setCursor(14, 1); lcd.print("OR"); } else { lcd.setCursor(14, 1); lcd.print("RO"); } } } //printing labels void printLabels() { lcd.clear(); if (sidePlayer == 1) { //seleted in menuSetUp lcd.setCursor(0, 0); lcd.print("ORANGE"); lcd.setCursor(11, 0); lcd.print("RED"); } else { lcd.setCursor(0, 0); lcd.print("RED"); lcd.setCursor(11, 0); lcd.print("ORANGE"); } lcd.setCursor(7, 1); lcd.print("||"); lcd.setCursor(6, 0); lcd.print("| |"); //this fix the print value below 10 moving the cursor one point and put 0 to left if ((setInc < 10) && (setInc >= 0)) { lcd.setCursor(7, 0); lcd.print(0); lcd.print(setInc); lcd.setCursor(8, 0); } else { lcd.setCursor(7, 0); lcd.print(setInc); } tone(pinBuzzer, 4300); delay(150); tone(pinBuzzer, 3500); delay(150); digitalWrite(pinBuzzer, LOW); //printing timers values printTimerOrange(); printTimerRed(); } void pauseGameOrange() { //with game paused in timer orange, for exit is necessary push button red while (digitalRead(buttonRed) == 0) { //used to timer blink blinkTime = millis() - blinkDelay; //print < caracter blinking if (blinkTime >= initBlinkTime && blinkState == 1) { lcd.setCursor(5, 0); lcd.print(" "); blinkState = 0; initBlinkTime = millis(); } if (blinkTime >= initBlinkTime && blinkState == 0) { lcd.setCursor(5, 0); lcd.print("<"); blinkState = 1; initBlinkTime = millis(); } } lcd.setCursor(5, 0); lcd.print(" "); } void pauseGameRed() { //with game paused in timer orange, for exit is necessary push button red while (digitalRead(buttonOrange) == 0) { //used to timer blink blinkTime = millis() - blinkDelay; //print > caracter blinking if (blinkTime >= initBlinkTime && blinkState == 1) { lcd.setCursor(10, 0); lcd.print(" "); blinkState = 0; initBlinkTime = millis(); } if (blinkTime >= initBlinkTime && blinkState == 0) { lcd.setCursor(10, 0); lcd.print(">"); blinkState = 1; initBlinkTime = millis(); } } lcd.setCursor(10, 0); lcd.print(" "); } //running timer orange void timerOrange() { //cSecOrange is a counter that will increase with millis() due SEC define. //The variable cSecOrange is updated in Arduino loop() (cSecOrange = SEC - cTemp). //seconds timer (secOrange) = seconds selected in menu set up (setSecOrange) minus //cSecOrange that will increase with milles() due SEC define. secOrange = setSecOrange - cSecOrange; printTimerOrange(); //update values //* making the timer *// //if seconds timer below 0(-1) and minutes >=0 plus counter seconds with 59 to //setSecOrange update the value and remove 1 in minutes timer if ((secOrange == -1) && (minOrange >= 0)) { setSecOrange = cSecOrange + 59; //update setSecOrange minOrange--; } //if seconds and minutes timer below 0(-1) and hour is > 0 plus 59 to //setSecOrange update the value,put minutes to 59 and remove 1 to hour if ((secOrange == -1) && (minOrange == -1) && (horOrange > 0)) { setSecOrange = cSecOrange + 59; minOrange = 59; horOrange--; } //if seconds, minutes and hour timers go to 0 loop forever and print end game if ((secOrange == 0) && (minOrange == 0) && (horOrange == 0)) { tone(pinBuzzer, 4300); delay(150); tone(pinBuzzer, 3500); delay(150); while (1) { lcd.setCursor(10, 0); lcd.print(" "); digitalWrite(pinBuzzer, HIGH); delay(1000); lcd.setCursor(10, 0); lcd.print("WINNER"); digitalWrite(pinBuzzer, LOW); delay(1000); } } } //running timer red void timerRed() { secRed = setSecRed - cSecRed; printTimerRed(); //timer if ((secRed == -1) && (minRed >= 0)) { setSecRed = cSecRed + 59; minRed--; } if ((secRed == -1) && (minRed == -1) && (horRed > 0)) { setSecRed = cSecRed + 59; minRed = 59; horRed--; } //end game if ((secRed == 0) && (minRed == 0) && (horRed == 0)) { tone(pinBuzzer, 4300); delay(150); tone(pinBuzzer, 3500); delay(150); while (1) { lcd.setCursor(0, 0); lcd.print(" "); digitalWrite(pinBuzzer, HIGH); delay(1000); lcd.setCursor(0, 0); lcd.print("WINNER"); digitalWrite(pinBuzzer, LOW); delay(1000); } } } //increment to orange void incOrange() { if (setInc > 0) { secOrange = secOrange + setInc; //increment seconds to seconds timer cSecOrange = setSecOrange - secOrange; //start new count //if seconds timer + increment > 59 and < 120 add 1 to minutes and remove 60 seconds to seconds timer if (secOrange > 59 && secOrange < 120) { secOrange = secOrange - 60; cSecOrange = setSecOrange - secOrange; minOrange++; } //if seconds timer + increment > 119 add 2 to minutes and remove 120 seconds to seconds timer else if (secOrange > 119) { secOrange = secOrange - 120; cSecOrange = setSecOrange - secOrange; minOrange = minOrange + 2; } //if minutes timer > 59 add 1 to hour and remove 60 to minutes timer if (minOrange > 59) { minOrange = minOrange - 60; horOrange++; } printTimerOrange(); //print new values } } //increment to red void incRed() { if (setInc > 0) { secRed = secRed + setInc; cSecRed = setSecRed - secRed; if (secRed > 59 && secRed < 120) { secRed = secRed - 60; cSecRed = setSecRed - secRed; minRed++; } else if (secRed > 119) { secRed = secRed - 120; cSecRed = setSecRed - secRed; minRed = minRed + 2; } if (minRed > 59) { minRed = minRed - 60; horRed++; } printTimerRed(); } } void readEeprom() { //used in case Arduino was used in another aplication if (EEPROM.read(0) > 59) EEPROM.write(0, 0); if (EEPROM.read(1) > 59) EEPROM.write(1, 0); if (EEPROM.read(2) > 9) EEPROM.write(2, 0); if (EEPROM.read(3) > 99) EEPROM.write(3, 0); if (EEPROM.read(4) > 1) EEPROM.write(4, 1); //load values to variables secOrange = EEPROM.read(0); minOrange = EEPROM.read(1); horOrange = EEPROM.read(2); setInc = EEPROM.read(3); sidePlayer = EEPROM.read(4); } void writeEeprom() { //write values that have been selected to eeprom EEPROM.write(0, secOrange); EEPROM.write(1, minOrange); EEPROM.write(2, horOrange); EEPROM.write(3, setInc); EEPROM.write(4, sidePlayer); } //Arduino setup void setup() { //setup pins pinMode(buttonOrange, INPUT); //button Orange pinMode(buttonRed, INPUT); //button Red pinMode(analogPin, INPUT); //used in keypad pinMode(pinBuzzer, OUTPUT); //buzzer //start LCD lcd.begin(16, 2); lcd.clear(); //start message lcd.clear(); lcd.setCursor(0, 0); lcd.print("BOOMBA ASG"); lcd.setCursor(0, 1); lcd.print("Zegar Szachowy"); delay(2000); lcd.clear(); digitalWrite(pinBuzzer, HIGH); readEeprom(); //read eeprom values and load to variables while (exitMenu) { //start set up menu menuSetUp(); //keypad set up printMenu(); //print menu values printTimerOrange(); //print setup timer in left below } writeEeprom(); //write values selected to eeprom //setting up values for Orange and red to start timers horRed = horOrange; minRed = minOrange; secRed = secOrange; setSecRed = secOrange; setSecOrange = secOrange; printLabels(); //printing labels } //Arduino loop void loop() { adc_key_in = analogRead(analogPin); //read keypad //push red button run orange timer if (digitalRead(buttonRed)) { tone(pinBuzzer, 4300); delay(150); tone(pinBuzzer, 3500); delay(150); cTemp = SEC - cSecOrange; //difference between SEC and previous seconds count while (digitalRead(buttonOrange) == 0 && adc_key_in > 1000) { //if orange button or any keypad pushed exit loop cSecOrange = SEC - cTemp; //second count for orange timer timerOrange(); //run timer orange adc_key_in = analogRead(analogPin); //read keypad } if (adc_key_in < 1000) { //if any keypad pushed go to pause pauseGameOrange(); } else { incOrange(); //increment seconds } } //push orange button run red timer if (digitalRead(buttonOrange)) { tone(pinBuzzer, 4300); delay(150); tone(pinBuzzer, 3500); delay(150); cTemp = SEC - cSecRed; while (digitalRead(buttonRed) == 0 && adc_key_in > 1000) { cSecRed = SEC - cTemp; timerRed(); adc_key_in = analogRead(analogPin); } if (adc_key_in < 1000) { pauseGameRed(); } else { incRed(); } } } Cytuj Link do komentarza Share on other sites More sharing options...
Pomocna odpowiedź
Dołącz do dyskusji, napisz odpowiedź!
Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!