JS Taschenrechner, Dezimal in Binär und andersherum auch?

Hallo Zusammen,
ich bin seit knapp 3 Wochen in meiner Ausbildung und sollte einen Taschenrechner programmieren, was bis jetzt auch geklappt hat. Nun habe ich eine neue Aufgabe dazu bekommen, nämlich mit 2 Radio Buttons mir jeweils anzeigen zu lassen: Binär und Dezimal.
Ich bin absolut hilflos und freue mich über mögliche Lösungen und HIlfe. Danke im voraus.

<!DOCTYPE html>
<html lang="de">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Taschenrechner No. 3</title>
      <script>
         let aktuellesErgebnis = 0;
         let modus;
         let aktuelleZahl;
         function AddLetter(zahl)
         {
         if(modus == null) 
         {
         document.getElementById("textboxDisplay").value = zahl;
         modus = "Nummern";
         }
         else
         {
         document.getElementById("textboxDisplay").value += zahl;
         }
         }
         function Plus()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = "";
         modus = "Plus";
         }
         function Minus()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = "";
         modus = "Minus";
         }
         function Mal()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = "";
         modus = "Mal"
         }
         function Geteilt()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = "";
         modus = "Geteilt"
         }
         function Restwert()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = "";
         modus = "Modulo"
         }
         function Gleich()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = aktuellesErgebnis;
         modus = null;
         }
         function Hilfe()
         {
         aktuelleZahl = Number(document.getElementById("textboxDisplay").value);
         if(modus == "Plus")
         {
         aktuellesErgebnis += aktuelleZahl;
         }
         if(modus == "Minus")
         {
         aktuellesErgebnis -= aktuelleZahl;
         }
         if(modus == "Mal")
         {
         aktuellesErgebnis *= aktuelleZahl;
         }
         if(modus == "Geteilt")
         {
         aktuellesErgebnis /= aktuelleZahl;
         }
         if(modus == "Modulo")
         {
         aktuellesErgebnis %= aktuelleZahl;
         }
         if(modus == null || modus == "Nummern")
         {
         aktuellesErgebnis = aktuelleZahl;
         }
         }
         function Weg()
         {
         document.getElementById("textboxDisplay").value = "";
         aktuellesErgebnis = 0;
         modus = null;
         }
      </script>
   </head>
   <body>
      <input type="radio" name="Umrechnung" value="Binär" />
      <input type="radio" name="Umrechnung" value="Dezimal" />
      <input id="textboxDisplay" readonly />
      <input type="button" value="1" onclick="AddLetter('1')" />
      <input type="button" value="2" onclick="AddLetter('2')" />
      <input type="button" value="3" onclick="AddLetter('3')" />
      <input type="button" value="4" onclick="AddLetter('4')" />
      <input type="button" value="5" onclick="AddLetter('5')" />
      <input type="button" value="6" onclick="AddLetter('6')" />
      <input type="button" value="7" onclick="AddLetter('7')" />
      <input type="button" value="8" onclick="AddLetter('8')" />
      <input type="button" value="9" onclick="AddLetter('9')" />
      <input type="button" value="0" onclick="AddLetter('0')" />
      <input type="button" value="+" onclick="Plus()" />
      <input type="button" value="-" onclick="Minus()" />
      <input type="button" value="*" onclick="Mal()" />
      <input type="button" value="/" onclick="Geteilt()" />
      <input type="button" value="Mod" onclick="Restwert()" />
      <input type="button" value="Löschen" onclick="Weg()" />
      <input type="button" value="=" onclick="Gleich()" />
   </body>
</html>
HTML, Webseite, JavaScript, Code, Programmiersprache
Wie bekomme ich den ESP32-WROOM-32 in den Boot Modus?

Hallo,

ich versuche bereits seit gestern, ein Skript auf meinen ESP32 zu laden. Wenn ich das mit der Arduino IDE mache, blinkt der ESP beim Hochladen nicht. Deshalb habe ich mir ein Python-Skript geschrieben, welches den ESP32 normalerweise automatisch flashen und das Skript hochladen sollte. Tatsächlich blinkt er nun beim Ausführen des Codes, allerdings tritt direkt nach der Verbindung ein Fehler auf:

esptool.py v4.7.0
Serial port COM3
Connecting......................................
Fehler beim Flashen der Firmware: Failed to connect to ESP32: Invalid head of packet (0xFF): Possible serial noise or corruption.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html

hier übrigens der Code;

import esptool

def flash_esp32(port, baudrate, firmware_path):
    try:
        esptool.main([
            '--chip', 'esp32',
            '--port', port,
            '--baud', str(baudrate),
            'write_flash', '-z',
            '0x1000', firmware_path
        ])
        print("Firmware erfolgreich geflasht.")
    except Exception as e:
        print(f"Fehler beim Flashen der Firmware: {e}")

if __name__ == '__main__':
    port = 'COM3' 
    baudrate = 9600  
    firmware_path = r'C:\Users\Julian.DESKTOP-J7KSTFA\Documents\Arduino\PGS\PGS.ino'  

    flash_esp32(port, baudrate, firmware_path)
Arduino, Code, Programmiersprache, Python, Arduino IDE
Warum funktioniert mein Arduino Code nicht?

Ich möchte mit einem Sensor einen Sound abspielen und wenn der Sensor ausgeht, soll ein Verabschiedungssound gespielt werden.

Ich benutze Arduino Nano und DfPlayer Mini.

Es wird kein Sound abgespielt.

Danke im Voraus.

Der Code lautet:

#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

// DFPlayer Mini setup
SoftwareSerial mySoftwareSerial(2, 3); // RX, TX for DFPlayer Mini
DFRobotDFPlayerMini dfPlayer;

const int seatMatPin = 7; // Pin connected to seat occupancy mat
bool wasSeated = false;

void setup()
{
  // Start serial communication for debugging
  Serial.begin(9600); // Start serial communication at 9600 baud rate

  // Initialize serial for DFPlayer Mini
  mySoftwareSerial.begin(9600);

  // Try to start DFPlayer Mini
  if (!dfPlayer.begin(mySoftwareSerial)) {
    Serial.println("DFPlayer Mini konnte nicht gestartet werden."); // Print error message
    while (true); // Stop execution here if DFPlayer Mini fails to start
  }

  Serial.println("DFPlayer Mini bereit."); // Print success message

  // Initialize seat mat pin
  pinMode(seatMatPin, INPUT_PULLUP); // Assuming mat signal is active LOW
}

void loop()
{
  // Read seat mat state
  bool isSeated = digitalRead(seatMatPin) == LOW; // LOW means seat is occupied

  if (isSeated && !wasSeated) {
    // Seat was just occupied
    Serial.println("Sitz wurde besetzt. Begrüßungsmelodie abspielen."); // Print message
    dfPlayer.play(1); // Play greeting sound
    wasSeated = true;
  }
  else if (!isSeated && wasSeated) {
    // Seat was just vacated
    Serial.println("Sitz wurde verlassen. Verabschiedungsmelodie abspielen."); // Print message
    dfPlayer.play(2); // Play farewell sound
    wasSeated = false;
  }

  delay(100); // Small delay for stability
}
Arduino, Code, Programmiersprache, Arduino Nano, Arduino IDE

Meistgelesene Beiträge zum Thema Programmiersprache