Skip to content

Commit

Permalink
day21
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepMartiElias committed Dec 20, 2023
1 parent 29c7bd1 commit 23449bb
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ hide:
1. How should I be called in the future?

!!! bug annotate "21. ChatGPT can you help me write a Cristmas card? (1)"
[Day 21](solutions/21/21.md)
1. From the Barduino?

!!! example annotate "22. Let's send it to someone (1)"
Expand Down
106 changes: 106 additions & 0 deletions docs/solutions/21/21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Day twenty one:

Use the Barduino to ask ChatGPT to create a Christmas Card text with the ChatGPT API. With the ChatGPT Arduino library you caan send prompts directly through the Barduino.

!!! danger "ChtGPT API"
To be able to use this function you need a ChatGPT API Key. Xavi Dominguez created one for tis challenge from his personal account, use it wisely as it will have a cost for him for every prompt sended. Do NOT send propmts directly on the loop, use a button or something to send it only one time. It can take some time to get an answer.

## Possible solution!

### Arduino code

```c++
#include <ArduinoJson.h>
#include <ArduinoJson.hpp>

#include <WiFiClientSecure.h>
#include <ChatGPT.hpp>
#include <Adafruit_NeoPixel.h>

static const char *ssid = "yournetwork";
static const char *password = "yourpassword";

WiFiClientSecure client;
ChatGPT<WiFiClientSecure> chat_gpt(&client, "v1", "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");


#define PIN 38

#define NUMPIXELS 1

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

String result;

void setup() {

Serial.begin(115200);
Serial.print("Connecting to WiFi network: ");
Serial.print(ssid);
Serial.println("'...");
WiFi.begin(ssid, password);
pixels.begin();

while (WiFi.status() != WL_CONNECTED) {
Serial.println("Connecting...");
delay(500);
}
Serial.println("Connected!");

// Ignore SSL certificate validation
client.setInsecure();

}

void loop() {
int touch = touchRead(2);

if(touch>29000){
pixels.setPixelColor(0, pixels.Color(0, 150, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(500); // Pause before next pass through loop
}else{
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(500); // Pause before next pass through loop
}



if(touch>300000){
Serial.println(touch);
if (chat_gpt.simple_message("gpt-4", "user", "Can you create for me a Christmas card with an ASCII drawing and a text for the Adventronics participants? Signed with love from Josep, please.", result)) {
Serial.println("===OK===");
Serial.println(result);
} else {
Serial.println("===ERROR===");
Serial.println(result);
}
}
Serial.println(touch);
delay(500);
}
```
## Hero shot
_____________________⛄_____________________
| |
| 👋 Hello, Adventronics participants! |
| |
| 🌟 * * 🎄** * 🎅 * |
| * * 🎁 * * 🕯️ * |
| * * ⭐* * 🌟 * * * |
| |
| Wishing you a Merry Christmas! May |
| this holiday season bring Joy, Peace |
| and Happiness to you and your loved ones |
| |
| With love, |
| Josep |
|_____________________❄️____________________|
<video controls autoplay loop style="display: block; margin: auto;">
<source src="../../../video/day21.mp4" type="video/mp4">
</video>
Binary file added docs/video/day21.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ nav:
- Day 18: solutions/18/18.md
- Day 19: solutions/19/19.md
- Day 20: solutions/20/20.md
- Day 21: solutions/21/21.md
- Solution template:
- template.md

Expand Down

0 comments on commit 23449bb

Please sign in to comment.