// Include necessary libraries #include #include #include #include #include // WiFi credentials const char* ssid = "thetempleofdoom"; const char* password = "myhandsonmyself"; // Gemini API key const char* geminiApiKey = "AIzaSyAzFzg_MAcwoH3O-nfriBjlFw5x6UBU5hk"; // Pin for the button // IMPORTANT: Please verify the pin number for your button and update the value below. const int buttonPin = 0; // Display pins // IMPORTANT: Please verify the pin numbers for your display and update the values below. #define TFT_CS 5 #define TFT_DC 4 #define TFT_RST -1 // Reset pin (often not needed) Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST); void setup() { // Initialize serial communication Serial.begin(115200); // Initialize the button pin pinMode(buttonPin, INPUT_PULLUP); // Connect to WiFi WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println("Connected to WiFi"); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); // Initialize the display tft.begin(); tft.setRotation(3); tft.fillScreen(ILI9341_BLACK); tft.setTextColor(ILI9341_GREEN); tft.setTextSize(2); tft.println("Hacker Voice Assistant"); tft.println("--------------------"); tft.setTextSize(1); tft.print("IP: "); tft.println(WiFi.localIP()); tft.setTextSize(2); tft.println("\nReady for command..."); } void loop() { // Check if the button is pressed if (digitalRead(buttonPin) == LOW) { // Start a voice session startVoiceSession(); // After the session, clear the screen and show the ready message again tft.fillScreen(ILI9341_BLACK); tft.setCursor(0,0); tft.setTextSize(2); tft.println("Hacker Voice Assistant"); tft.println("--------------------"); tft.setTextSize(1); tft.print("IP: "); tft.println(WiFi.localIP()); tft.setTextSize(2); tft.println("\nReady for command..."); } } void startVoiceSession() { // Clear the screen for the new session tft.fillScreen(ILI9341_BLACK); tft.setCursor(0,0); tft.setTextSize(2); // TODO: Add voice recording and processing code here Serial.println("Button pressed, starting voice session..."); displayHackerText("Listening..."); // For now, we'll just send a test query to Gemini delay(2000); // Simulate recording time displayHackerText("Processing..."); String query = "Hello, Gemini!"; String response = sendToGemini(query); // Display the response displayHackerText("User: " + query); displayHackerText("Gemini: " + response); Serial.println("Gemini response: " + response); } String sendToGemini(String query) { HTTPClient http; String url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key="; url += geminiApiKey; http.begin(url); http.addHeader("Content-Type", "application/json"); StaticJsonDocument<200> doc; JsonObject content = doc.createNestedObject("contents"); JsonArray parts = content.createNestedArray("parts"); JsonObject part = parts.createNestedObject(); part["text"] = query; String requestBody; serializeJson(doc, requestBody); int httpResponseCode = http.POST(requestBody); if (httpResponseCode > 0) { String payload = http.getString(); StaticJsonDocument<1024> responseDoc; DeserializationError error = deserializeJson(responseDoc, payload); if (error) { Serial.print(F("deserializeJson() failed: ")); Serial.println(error.f_str()); return "Error: Failed to parse response."; } if (responseDoc.containsKey("candidates")) { const char* responseText = responseDoc["candidates"][0]["content"]["parts"][0]["text"]; return String(responseText); } else { return "Error: Invalid response from Gemini."; } } else { Serial.print("Error on sending POST: "); Serial.println(httpResponseCode); return "Error: Unable to get response from Gemini."; } http.end(); return ""; } void displayHackerText(String text) { tft.println(text); }