Advertisement
pleasedontcode

WiFi Displays rev_01

Sep 27th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: WiFi Displays
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-09-27 09:10:30
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system shall utilize the LCDIC2 library to */
  21.     /* display real-time data on an I2C LCD screen, */
  22.     /* interfacing through SDA and SCL pins defined in */
  23.     /* the code. It will also connect to the Cohere */
  24.     /* Client for cloud communication. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Wire.h>
  29. #include <LCDIC2.h> // https://github.com/offcircuit/LCDIC2
  30. #include <WiFiClientSecure.h>
  31. #include <cohereclient.hpp> // https://github.com/ejri/Cohere_Client_Arduino
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. /***** DEFINITION OF I2C PINS *****/
  38. const uint8_t Lethal_LCD1602I2C_I2C_PIN_SDA_D21     = 21; // SDA pin
  39. const uint8_t Lethal_LCD1602I2C_I2C_PIN_SCL_D22     = 22; // SCL pin
  40. const uint8_t Lethal_LCD1602I2C_I2C_SLAVE_ADDRESS       = 39; // I2C address for the LCD
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  43. // Initialize the LCDIC2 object with the I2C address and dimensions
  44. LCDIC2 lcd(Lethal_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // 16 columns and 2 rows
  45.  
  46. // Initialize WiFiClientSecure for secure connections
  47. WiFiClientSecure client;
  48.  
  49. // Initialize CohereClient with the WiFiClientSecure instance and your API key
  50. #define YOUR_API_KEY "YOUR_API_KEY" // Replace with your actual API key
  51. CohereClient cohereClient(&client, YOUR_API_KEY);
  52.  
  53. // Define parameters for API calls
  54. int max_tokens = 200; // Maximum tokens for the API call
  55. String prompt = "Once upon a time in a magical land called"; // Prompt for the API call
  56.  
  57. void setup(void)
  58. {
  59.     Serial.begin(115200); // Initialize serial communication for debugging
  60.    
  61.     // Initialize the LCD
  62.     lcd.begin();
  63.     // Print a welcome message on the LCD
  64.     lcd.print("Initializing...");
  65.  
  66.     // Connect to WiFi
  67.     WiFi.begin("WIFI_SSID", "WIFI_PW"); // Replace with your WiFi credentials
  68.     while (WiFi.status() != WL_CONNECTED)
  69.     {
  70.         delay(500);
  71.         Serial.println("Connecting to WiFi...");
  72.     }
  73.     Serial.println("Connected to WiFi");
  74.     lcd.clear(); // Clear the LCD for new output
  75.     lcd.print("WiFi Connected"); // Display connection status on the LCD
  76. }
  77.  
  78. void loop(void)
  79. {
  80.     // Make an API call to Cohere and get the response
  81.     String response = cohereClient.makeAPICall(max_tokens, prompt);
  82.    
  83.     // Print the text output from the response
  84.     String output = cohereClient.text_output(response);
  85.     lcd.clear(); // Clear the LCD for new output
  86.     lcd.print(output); // Display the output on the LCD
  87.     Serial.println(output); // Print output to Serial Monitor
  88.     delay(5000); // Wait for 5 seconds
  89.  
  90.     // Print the full response for debugging
  91.     Serial.println("");
  92.     String fullResponse = cohereClient.full_response(response);
  93.     Serial.println(fullResponse);
  94.     delay(5000); // Wait for 5 seconds before the next loop
  95. }
  96.  
  97. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement