Components and supplies
Arduino-based TME Edu Kit rev2.
Apps and platforms
Arduino IDE
Project description
Code
Code
cpp
1/* 2 This program have been made by the team "CONNECT" for the 2024 ARDUINO DAYS's hackathon in Benin at Seme City Open Park. 3 The hardware used has the TME basic kit. The objectif of the hackaton was to use the most components 4 of the kit to create some univers with buzzer, RGB LEDs, 7 segments displays, LCD display, OLED display, potentiometer and push buttons. 5 Members of the team : 6 1++ 7 2++ 8 3++ 9 4++ 10 5++ 11 6++ 12*/ 13 14//Library for the 16*2 LCD used with a port expender MCP23008 15#include<Wire.h> 16#include <hd44780.h> 17#include <hd44780ioClass/hd44780_I2Cexp.h> 18hd44780_I2Cexp lcd(0x20, I2Cexp_MCP23008,7,6,5,4,3,2,1,HIGH); 19 20//Library for the digitaly controlled RGB LED 21#include <Adafruit_NeoPixel.h> 22Adafruit_NeoPixel Pixels= Adafruit_NeoPixel(5,12,NEO_GRB+ NEO_KHZ800); 23 24//Library for the 7 segments display used with a port expender MCP23008 25#include <Adafruit_MCP23008.h> 26Adafruit_MCP23008 seg7; 27uint8_t digit[10]= 28{ 29B01110111,//A 30B01010000,//r 31B01011110,//d 32B00011100,//u 33B00010000,//i 34B01010100,//n 35B01011100,//o 36B01011110,//d 37B01011111,//a 38B01101110,//y 39}; 40 41 42#include <SPI.h> 43#include <Adafruit_GFX.h> 44#include <Adafruit_SSD1306.h> 45#define SCREEN_WIDTH 128 // OLED display width 46#define SCREEN_HEIGHT 64 // OLED display height 47#define OLED_RESET -1 // OLED display's reset pin not used 48#define SCREEN_ADDRESS 0x3C // OLED display's I2C address 49#define BLUE 0x0000FF 50#define RED 0xFF0000 51#define YELLOW 0xFFFF00 52Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 53 54#include "pitches.h" // file countaining various sound's frequencies 55 56#define R 9 // red LED in the RGB LED 57#define G 10 // green LED in the RGB LED 58#define B 11 // blue LED in the RGB LED 59#define led1 13 // blue LED connected on the pin 3 60#define MICROPHONE_PIN A0 61#define BUZZER_PIN 2 62 63// Planet's positions in the animation of OLED display 64int sunX = 20; 65int sunY = 20; 66int mercuryX = 40; 67int mercuryY = 40; 68int venusX = 60; 69int venusY = 60; 70int earthX = 80; 71int earthY = 80; 72int marsX = 100; 73int marsY = 100; 74 75bool univers1 = false; 76bool univers2 = false; 77bool univers3 = false; 78bool univers4 = false; 79 80void setup() 81{ 82 83 Wire.begin(); 84 Pixels.begin(); 85 lcd.begin(16,2); 86 87 seg7.begin(0x4); 88 seg7.pinMode(0,OUTPUT); 89 seg7.pinMode(1,OUTPUT); 90 seg7.pinMode(2,OUTPUT); 91 seg7.pinMode(3,OUTPUT); 92 seg7.pinMode(4,OUTPUT); 93 seg7.pinMode(5,OUTPUT); 94 seg7.pinMode(6,OUTPUT); 95 seg7.pinMode(7,OUTPUT); 96 97 display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); 98 99 pinMode(R,OUTPUT); 100 pinMode(G,OUTPUT); 101 pinMode(B,OUTPUT); 102 pinMode(led1,OUTPUT); 103 pinMode(BUZZER_PIN, OUTPUT); 104 105} 106 107void loop() 108{ 109 light(); // Welcome animation 110 111 // UNIVERS1:Planet of senses 112 if(digitalRead (6)==HIGH) 113 { 114 univers1 = true; 115 lcd.clear(); 116 } 117 while(univers1== true){ 118 119 lcd.setCursor(4,0); 120 lcd.print("UNIVERS1"); 121 lcd.setCursor(0,1); 122 lcd.print("Planet of senses"); 123 planet_of_senses(); 124 125 if(digitalRead(8)==HIGH) 126 { 127 univers1 = false; 128 } 129 } 130 131 //UNIVERS 2: Sound's cave 132 133 if(digitalRead (7)==HIGH) 134 { 135 univers2 = true; 136 lcd.clear(); 137 } 138 while(univers2== true) 139 { 140 141 lcd.setCursor(4,0); 142 lcd.print("UNIVERS2"); 143 lcd.setCursor(1,1); 144 lcd.print("Sound's cave"); 145 sound_cave(); 146 147 if(digitalRead(8)==HIGH) 148 { 149 univers2= false; 150 } 151 } 152 153 //UNIVERS 3 :Star's ocean 154 if(digitalRead (5)==HIGH) 155 { 156 univers3 = true; 157 lcd.clear(); 158 } 159 while(univers3== true) 160 { 161 lcd.setCursor(4,0); 162 lcd.print("UNIVERS3"); 163 lcd.setCursor(1,1); 164 lcd.print("Star's Ocean"); 165 Star_ocean(); 166 167 if(digitalRead(8)==HIGH) 168 { 169 univers3 = false; 170 } 171 } 172 173 //UNIVERS 4 : Shooting stars 174 if(digitalRead (4)==HIGH) 175 { 176 univers4 = true; 177 lcd.clear(); 178 } 179 180 while(univers4== true) 181 { 182 lcd.setCursor(4,0); 183 lcd.print("UNIVERS4"); 184 lcd.setCursor(1,1); 185 lcd.print("Shooting stars"); 186 displayWaveAnimation(); 187 Shooting_stars(); 188 189 if(digitalRead(8)==HIGH) 190 { 191 univers4 = false; 192 } 193 } 194} 195 196void light() 197{ 198 lcd.setCursor(2,0); 199 lcd.print("ARDUINO DAYS"); 200 lcd.setCursor(2,1); 201 lcd.print("TEAM CONNECT"); 202 203 playTone(392, 300); // Sol (G) 204 playTone(329, 200); // Mi (E) 205 playTone(293, 300); // Ré (D) 206 playTone(261, 200); // Do (C) 207 playTone(392, 300); // Sol (G) 208 209 digitalWrite(led1,HIGH); 210 delay(500); 211 analogWrite( B,255); 212 delay(500); 213 controle_bleu(); 214 delay(500); 215 digitalWrite(led1,LOW); 216 controle_any(); 217 analogWrite( B,0); 218 delay(500); 219 controle_bleu(); 220 delay(500); 221 analogWrite( B,255); 222 delay(500); 223 digitalWrite(led1,HIGH); 224 delay(500); 225 digitalWrite(led1,LOW); 226 227 playTone(329, 200); // Mi 228 playTone(293, 300); // Ré 229 playTone(261, 200); // Do 230 playTone(392, 300); // Sol 231 violet(); 232 233 controle_violet(); 234 delay(500); 235 236 controle_any(); 237 any(); 238 delay(500); 239 violet(); 240 controle_violet(); 241 delay(500); 242 controle_any(); 243 any(); 244 delay(500); 245 246 controle_any(); 247 delay(500); 248 playTone(329, 200); // Mi 249 playTone(293, 300); // Ré 250 playTone(261, 200); // Do 251 playTone(440, 500); // La 252 controle_any(); 253 delay(500); 254 255 violet(); 256 controle_violet(); 257 delay(1000); 258 controle_any(); 259 any(); 260 delay(500); 261 controle_any(); 262 delay(3000); 263 violet(); 264 controle_violet(); 265 delay(5000); 266} 267 268void playTone(int frequency, int duration) 269{ 270 tone(BUZZER_PIN, frequency, duration); 271 delay(duration + 50); 272} 273 274void controle_bleu(void) // produce blue color on digitaly controled RGB LED WS2812 275{ 276 Pixels.setPixelColor(0,Pixels.Color(10,20,30)); 277 Pixels.setPixelColor(1,Pixels.Color(10,20,30)); 278 Pixels.setPixelColor(2,Pixels.Color(10,20,30)); 279 Pixels.setPixelColor(3,Pixels.Color(10,20,30)); 280 Pixels.setPixelColor(4,Pixels.Color(10,20,30)); 281 Pixels.show(); 282} 283 284void controle_any(void) // turn off digitaly controled RGB LED WS2812 285{ 286 Pixels.setPixelColor(0,Pixels.Color(0,0,0)); 287 Pixels.setPixelColor(1,Pixels.Color(0,0,0)); 288 Pixels.setPixelColor(2,Pixels.Color(0,0,0)); 289 Pixels.setPixelColor(3,Pixels.Color(0,0,0)); 290 Pixels.setPixelColor(4,Pixels.Color(0,0,0)); 291 Pixels.show(); 292} 293 294void controle_violet()// produce violet color on digitaly controled RGB LED WS2812 295{ 296 Pixels.setPixelColor(0,Pixels.Color(153,0,153)); 297 Pixels.setPixelColor(1,Pixels.Color(153,0,153)); 298 Pixels.setPixelColor(2,Pixels.Color(153,0,153)); 299 Pixels.setPixelColor(3,Pixels.Color(153,0,153)); 300 Pixels.setPixelColor(4,Pixels.Color(153,0,153)); 301 Pixels.show(); 302} 303 304void any ()//Turn off normal RGB LED 305{ 306 analogWrite(R,0); 307 analogWrite(G,0); 308 analogWrite(B,0); 309} 310 311void displayMoon() 312{ 313 display.fillCircle(10, 10, 8, WHITE); 314 display.display(); 315 delay(2000); 316 display.clearDisplay(); 317} 318void displayAstronaut() 319{ 320 display.drawRect(80, 20, 8, 20, WHITE); 321 display.drawLine(84, 40, 88, 45, WHITE); 322 display.drawLine(84, 40, 80, 45, WHITE); 323 display.drawCircle(84, 18, 3, WHITE); 324 display.display(); 325 delay(2000); 326 display.clearDisplay(); 327} 328void displayStars() 329{ 330 for(int i = 0; i < 20; i++) 331 { 332 int x = random(SCREEN_WIDTH); 333 int y = random(SCREEN_HEIGHT); 334 display.drawPixel(x, y, WHITE); 335 } 336 display.display(); 337 delay(2000); 338 display.clearDisplay(); 339 340} 341 342void displayRocket() 343{ 344 345 display.drawRect(50, 20, 8, 40, WHITE); 346 display.drawTriangle(48, 20, 56, 20, 52, 12, WHITE); 347 display.drawCircle(54, 55, 5, WHITE); 348 display.display(); 349 delay(2000); 350 display.clearDisplay(); 351} 352void violet () // produce violet color on RGB LED 353{ 354 analogWrite(R,153); 355 analogWrite(G,0); 356 analogWrite(B,153); 357} 358void planet_of_senses() 359{ 360 int pot = analogRead(A1); 361 362 if( pot<=40) 363 { 364 seg7.writeGPIO(digit[0]); 365 tone(2,NOTE_CS4,250); 366 displayMoon(); 367 } 368 else if(pot>=45 && pot<= 80) 369 { 370 seg7.writeGPIO(digit[1]); 371 tone(2,NOTE_DS4 ,250); 372 displayAstronaut(); 373 } 374 else if(pot>=85 && pot<=120) 375 { 376 seg7.writeGPIO(digit[2]); 377 tone(2,NOTE_E4,250); 378 displayRocket(); 379 } 380 381 else if(pot>=125 && pot<=160) 382 { 383 seg7.writeGPIO(digit[3]); 384 tone(2,NOTE_FS4 ,250); 385 displayAstronaut(); 386 } 387 else if(pot>=165 && pot<=200) 388 { 389 seg7.writeGPIO(digit[4]); 390 tone(2,NOTE_GS4,250); 391 displayMoon(); 392 } 393 else if(pot>=205 && pot<=250) 394 { 395 seg7.writeGPIO(digit[5]); 396 tone(2,NOTE_AS4,250); 397 displayRocket(); 398 } 399 else if(pot>=255 && pot<=300) 400 { 401 seg7.writeGPIO(digit[6]); 402 tone(2,NOTE_B4,250); 403 displayMoon(); 404 } 405 else if(pot>=305 && pot<=350) 406 { 407 seg7.writeGPIO(digit[7]); 408 tone(2,NOTE_CS4,250); 409 displayAstronaut(); 410 } 411 else if(pot>=355 && pot<=400) 412 { 413 seg7.writeGPIO(digit[8]); 414 tone(2, NOTE_DS4 ,250); 415 displayMoon(); 416 } 417 else if(pot>=405 && pot<=450) 418 { 419 seg7.writeGPIO(digit[9]); 420 tone(2, NOTE_GS5 ,250); 421 displayAstronaut(); 422 } 423} 424 425void display_() 426{ updatePlanets(); 427 // Effacer l'écran 428 display.clearDisplay(); 429 // Dessiner les planètes mises à jour 430 drawPlanets(); 431 // Dessiner les étoiles 432 drawStars(); 433 // Afficher le contenu sur l'écran 434 display.display(); 435 // Attendre un court instant pour l'animation 436 delay(100); 437 438} 439 440 441 442void displayWaveAnimation() 443{ 444 for(int y = 0; y < SCREEN_HEIGHT; y += 4) 445 { 446 display.drawLine(0, y, SCREEN_WIDTH - 1, y, WHITE); 447 } 448 display.display(); 449 delay(2000); 450 display.clearDisplay(); 451} 452void sound_cave() 453{ 454 int microphoneValue = analogRead(MICROPHONE_PIN); 455 if (microphoneValue > 400) 456 { 457 playTone(153, 1000); 458 controle_violet(); 459 delay(1000) ; 460 } 461 controle_any(); 462 noTone(BUZZER_PIN); 463} 464 465void Star_ocean() 466{ 467 updatePlanets(); 468 display.clearDisplay(); 469 drawPlanets(); 470 drawStars(); 471 display.display(); 472 delay(100); 473} 474 475void updatePlanets() 476 { 477 sunX += 1; 478 if (sunX > SCREEN_WIDTH) 479 { 480 sunX = -10; 481 } 482 483 mercuryX += 1; 484 if (mercuryX > SCREEN_WIDTH) 485 { 486 mercuryX = -5; 487 } 488 489 venusY += 1; 490 if (venusY > SCREEN_HEIGHT) 491 { 492 venusY = -5; 493 } 494 495 earthX -= 1; 496 if (earthX < 0) 497 { 498 earthX = SCREEN_WIDTH + 5; 499 } 500 501 marsY -= 1; 502 if (marsY < 0) 503 { 504 marsY = SCREEN_HEIGHT + 5; 505 } 506} 507 508void drawPlanets() 509{ 510 511 display.fillCircle(sunX, sunY, 10, WHITE); 512 display.fillCircle(mercuryX, mercuryY, 3, WHITE); 513 display.fillCircle(venusX, venusY, 5, WHITE); 514 display.fillCircle(earthX, earthY, 5, BLUE); 515 display.fillCircle(marsX, marsY, 4, RED); 516 517} 518void drawStars() 519{ 520 521 for (int i = 0; i < 20; i++) 522 { 523 int x = random(SCREEN_WIDTH); 524 int y = random(SCREEN_HEIGHT); 525 display.drawPixel(x, y, WHITE); 526 } 527} 528 529void Shooting_stars() 530{ 531 for (int i = 0; i < 6; i++) 532 { 533 Pixels.setPixelColor(i, Pixels.Color(255, 103, 0)); 534 Pixels.show(); 535 delay(300); 536 Pixels.setPixelColor(i, Pixels.Color(0, 0, 0)); 537 } 538 }
Downloadable files
Pitches
pitches.h
Comments
Only logged in users can leave comments
mohamedsalifou801
4 months ago
Great Work Mahudjro !👏 Can you just please add a vidéo so WE Can see how it works !!! 😁