Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: WiFi Displays
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-09-27 09:10:30
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The system shall utilize the LCDIC2 library to */
- /* display real-time data on an I2C LCD screen, */
- /* interfacing through SDA and SCL pins defined in */
- /* the code. It will also connect to the Cohere */
- /* Client for cloud communication. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <LCDIC2.h> // https://github.com/offcircuit/LCDIC2
- #include <WiFiClientSecure.h>
- #include <cohereclient.hpp> // https://github.com/ejri/Cohere_Client_Arduino
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t Lethal_LCD1602I2C_I2C_PIN_SDA_D21 = 21; // SDA pin
- const uint8_t Lethal_LCD1602I2C_I2C_PIN_SCL_D22 = 22; // SCL pin
- const uint8_t Lethal_LCD1602I2C_I2C_SLAVE_ADDRESS = 39; // I2C address for the LCD
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
- // Initialize the LCDIC2 object with the I2C address and dimensions
- LCDIC2 lcd(Lethal_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // 16 columns and 2 rows
- // Initialize WiFiClientSecure for secure connections
- WiFiClientSecure client;
- // Initialize CohereClient with the WiFiClientSecure instance and your API key
- #define YOUR_API_KEY "YOUR_API_KEY" // Replace with your actual API key
- CohereClient cohereClient(&client, YOUR_API_KEY);
- // Define parameters for API calls
- int max_tokens = 200; // Maximum tokens for the API call
- String prompt = "Once upon a time in a magical land called"; // Prompt for the API call
- void setup(void)
- {
- Serial.begin(115200); // Initialize serial communication for debugging
- // Initialize the LCD
- lcd.begin();
- // Print a welcome message on the LCD
- lcd.print("Initializing...");
- // Connect to WiFi
- WiFi.begin("WIFI_SSID", "WIFI_PW"); // Replace with your WiFi credentials
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.println("Connecting to WiFi...");
- }
- Serial.println("Connected to WiFi");
- lcd.clear(); // Clear the LCD for new output
- lcd.print("WiFi Connected"); // Display connection status on the LCD
- }
- void loop(void)
- {
- // Make an API call to Cohere and get the response
- String response = cohereClient.makeAPICall(max_tokens, prompt);
- // Print the text output from the response
- String output = cohereClient.text_output(response);
- lcd.clear(); // Clear the LCD for new output
- lcd.print(output); // Display the output on the LCD
- Serial.println(output); // Print output to Serial Monitor
- delay(5000); // Wait for 5 seconds
- // Print the full response for debugging
- Serial.println("");
- String fullResponse = cohereClient.full_response(response);
- Serial.println(fullResponse);
- delay(5000); // Wait for 5 seconds before the next loop
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement