element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Quiz button
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 5 replies
  • Subscribers 388 subscribers
  • Views 935 views
  • Users 0 members are here
Related

Quiz button

FADHLAN2008
FADHLAN2008 over 2 years ago

Hello everyone. Please help...
#include "DFRobotDFPlayerMini.h"
#include "SoftwareSerial.h"

// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 2; // connect to pin 2 on the DFPlayer via a 1K resistor
static const uint8_t PIN_MP3_RX = 3; // connect to pin 3 on the DFPlayer

// Software serial library
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
// Player
DFRobotDFPlayerMini player;

// Pins for buttons
const unsigned char switches[4] = {A7, A6, A5, A4};

// Pins for LEDs
const unsigned char leds[4] = {4, 5, 6, 7};

// Reset button
const unsigned char switch_reset = A2;

// Prepare the Arduino
void setup() {
// Prepare the pins

pinMode(switch_reset, INPUT_PULLUP);
for (unsigned char sw=0; sw<4; sw++) {
pinMode(switches[sw], INPUT_PULLUP);
pinMode(leds[sw], OUTPUT);
digitalWrite(leds[sw], LOW);
}

// Init serial port for DFPlayer Mini
softwareSerial.begin(9600);
// Start communication with DFPlayer Mini
if (player.begin(softwareSerial)) player.volume(30);
player.play(11);
while (digitalRead(switch_reset) == HIGH) {};
// Stop any playing sfx
player.stop();
}

// Main loop
void loop() {
// Check all 4 switches
for (unsigned char sw=0; sw<4; sw++) {
// Is it pressed?
if (digitalRead(switches[sw]) == LOW) {
// Turn on its LED
digitalWrite(leds[sw], HIGH);
// Play its sfx
player.play(sw+1);
// Wait for the reset button
while (digitalRead(switch_reset) == HIGH) {};
// Stop any playing sfx
player.stop();
// Turn off the LED
digitalWrite(leds[sw], LOW);
// Stop!
break;
}
}
}

how to add button right and button wrong answer before reset after arduino pins A4-A7 are pressed

  • Sign in to reply
  • Cancel

Top Replies

  • Gough Lui
    Gough Lui over 2 years ago +1
    Please insert code using the Insert -> Code option, as otherwise your code is mangled and difficult to read. You will need to explain exactly what it needs to do, how it works at the moment and what…
Parents
  • robogary
    robogary over 2 years ago

    What is the desired functionality of the right answer and wrong answer button for the DFplayer? 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • robogary
    robogary over 2 years ago

    What is the desired functionality of the right answer and wrong answer button for the DFplayer? 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube