C++ 如何放置'';WinneMessage'';在Arduino'';西蒙说'';代码
我的西蒙·赛义德项目真的需要一些帮助。我只想在代码中添加一个winnermessage,比如当游戏达到一级一级的时候,“你赢了”。 我想我什么都试过了,但显然没有。帮我阻止我的头发变白 我不知道写什么或者把代码放在哪里 这是ived使用的代码:C++ 如何放置'';WinneMessage'';在Arduino'';西蒙说'';代码,c++,arduino,void,C++,Arduino,Void,我的西蒙·赛义德项目真的需要一些帮助。我只想在代码中添加一个winnermessage,比如当游戏达到一级一级的时候,“你赢了”。 我想我什么都试过了,但显然没有。帮我阻止我的头发变白 我不知道写什么或者把代码放在哪里 这是ived使用的代码: */ #define led7 7 //white button led #define led6 6 // green button led #define led5 5 // red button led #define l
*/
#define led7 7 //white button led
#define led6 6 // green button led
#define led5 5 // red button led
#define led8 8 // blue button led
#define button7 led7 + 4 //white button
#define button6 led6 + 4 // green button
#define button5 led5 + 4 // red button
#define button8 led8 + 4 //blue button
#define levelsInGame 5
#define buzzer 3
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//create an array for this game
int simonSaid[levelsInGame]; //initialise the array
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
// initialize digital pins as outputs for LEDS in the buttons.
pinMode(led7, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led8, OUTPUT);
digitalWrite(led7, LOW);
digitalWrite(led6, LOW);
digitalWrite(led5, LOW);
digitalWrite(led8, LOW);
pinMode(button7, INPUT_PULLUP); // set the button pins as inputs
pinMode(button6, INPUT_PULLUP);
pinMode(button5, INPUT_PULLUP);
pinMode(button8, INPUT_PULLUP);
randomSeed(analogRead(0)); //make our random numbers more random
// populate the array with random 'colours'
for (int i = 0; i <= levelsInGame; i++) {
simonSaid[i] = random(5, 9);
}
for(int j = 0; j < levelsInGame; j++) //Print this array to serial monitor
{
Serial.println(simonSaid[j]);
}
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(WHITE);
display.setCursor(1, 0);
display.println("Simon Says");
display.setTextSize(1); // Draw 1X-scale text
display.println(" by DIY Machines");
display.println("tinyurl.com/y2llr32t");
display.display(); // Show text
delay(2000);
}
// the loop function runs over and over again forever
void loop() {
bool gameOver = 0;
while (gameOver == 0) {
for (int i = 1; i < (levelsInGame + 1); i++) { // for each level
Serial.println();
Serial.print("Level ");
Serial.println(i);
if (i < 10){
display.clearDisplay(); //print level on screen
display.setTextSize(3); // Draw 3X-scale text
display.setTextColor(WHITE);
display.setCursor(1, 0);
display.print("Level ");
display.println(i);
display.display(); // Show text
delay(400);
} else {
display.clearDisplay(); //print level on screen in smaller text
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(WHITE);
display.setCursor(1, 0);
display.print(" Level ");
display.println(i);
display.display(); // Show text
delay(400);
}
for (int g = 0; g < i; g++) { //play the colours through to that level
Serial.print("Colour number ");
Serial.print(g + 1);
Serial.print(" in this sequance is the button on D");
Serial.println(simonSaid[g]);
digitalWrite(simonSaid[g], HIGH);
playBuzzer(simonSaid[g]);
delay(200);
digitalWrite(simonSaid[g], LOW);
delay(50);
}
for (int g = 0; g < i; g++) { //check the colours you enter for that level
Serial.print("Press the correct button for number ");
Serial.print(g + 1);
Serial.print(" in Simon's sequance which should be the one connected to pin D");
Serial.println(simonSaid[g]);
int sensorButton7 = 1;
int sensorButton6 = 1;
int sensorButton5 = 1;
int sensorButton8 = 1;
int buttonPressed = 0; //a button that does not exist
while (sensorButton5 == HIGH && sensorButton6 == HIGH && sensorButton7 == HIGH && sensorButton8 == HIGH) { //until a button is pressed keep checking all of them
sensorButton7 = digitalRead(button7);
//Serial.print("Sensor button 0 = ");
//Serial.println(sensorButton0);
sensorButton6 = digitalRead(button6);
//Serial.print("Sensor button 1 = ");
//Serial.println(sensorButton1);
sensorButton5 = digitalRead(button5);
//Serial.print("Sensor button 2 = ");
//Serial.println(sensorButton2);
sensorButton8 = digitalRead(button8);
//Serial.print("Sensor button 3 = ");
// Serial.println(sensorButton3);
}
delay(200); // a kind of debounce - maybe later swap it for a check that all buttons have been depressed for 100ms?
//record which one was pressed
if (sensorButton7 == 0) {
buttonPressed = 7;
}
else if (sensorButton6 == 0) {
buttonPressed = 6;
}
else if (sensorButton5 == 0) {
buttonPressed = 5;
}
else {
buttonPressed = 8;
}
Serial.print("Button that was pressed is = "); //print out the pressed button
Serial.println(buttonPressed);
digitalWrite(buttonPressed, HIGH); //turn on the button light
playBuzzer(buttonPressed); //make the sound of the button pressed - right or wrong
digitalWrite(buttonPressed, LOW); //turn off button light
//check to see if it is what should be pressed
if (buttonPressed == (simonSaid[g])) {
Serial.println("Correct button - well done");
}
else {
Serial.println("Wrong button was pressed.");
gameOver = 1;
Serial.println("Game finished - sorry. Better luck next time.");
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(WHITE);
display.setCursor(1, 0);
display.println("GAME OVER");
display.print("at lvl ");
display.print(i);
display.display(); // Show initial text
//display.startscrollleft(0x00, 0x0F);
tone(buzzer, 350); //play game over low tone on buzzer
digitalWrite(led7, HIGH); //turn on all the lights
digitalWrite(led6, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led8, HIGH);
delay(2000);
noTone(buzzer);
digitalWrite(led7, LOW); //turn oFF all the lights
digitalWrite(led6, LOW);
digitalWrite(led5, LOW);
digitalWrite(led8, LOW);
delay(2000);
softReset();
}
}
}
}
}
void softReset() {
asm volatile (" jmp 0");
}
void playBuzzer(int button) {
if (button == 5) {
tone(buzzer, 950);
delay(300);
noTone(buzzer);
}
else if (button == 6) {
tone(buzzer, 850);
delay(300);
noTone(buzzer);
}
else if (button == 7) {
tone(buzzer, 750);
delay(300);
noTone(buzzer);
}
else if (button == 8) {
tone(buzzer, 650);
delay(300);
noTone(buzzer);
}
}
*/
#定义led7//白色按钮led
#定义led6//绿色按钮led
#定义led5//红色按钮led
#定义led8/蓝色按钮led
#定义按钮7 led7+4//白色按钮
#定义按钮6 led6+4//绿色按钮
#定义按钮5 led5+4//红色按钮
#定义按钮8 led8+4//蓝色按钮
#定义levelsInGame 5
#定义蜂鸣器3
#包括
#包括
#包括
#包括
#定义屏幕宽度128//OLED显示宽度,以像素为单位
#定义屏幕高度32//OLED显示高度,以像素为单位
//连接到I2C(SDA、SCL引脚)的SSD1306显示器声明
#定义OLED_重置4//RESET pin#(如果共享Arduino重置pin,则为-1)
Adafruit_SSD1306显示器(屏幕宽度、屏幕高度和电线、OLED_重置);
//为这个游戏创建一个数组
int-simonSaid[levelsInGame]//初始化数组
//当您按下复位或接通电路板电源时,设置功能运行一次
无效设置(){
Serial.begin(9600);
//将数字管脚初始化为按钮中LED的输出。
引脚模式(led7,输出);
引脚模式(led6,输出);
引脚模式(led5,输出);
引脚模式(led8,输出);
数字写入(led7,低电平);
数字写入(led6,低电平);
数字写入(led5,低电平);
数字写入(led8,低电平);
pinMode(button7,INPUT_PULLUP);//将按钮引脚设置为输入
pinMode(按钮6,输入\上拉);
pinMode(按钮5,输入\上拉);
pinMode(按钮8,输入\上拉);
randomSeed(analogRead(0));//使我们的随机数更随机
//使用随机“颜色”填充阵列
对于(int i=0;我在这里打招呼,欢迎来到stackoverflow。在它当前的状态下,您的问题有点模糊:您显示了很多代码-如果它不是您自己的代码,添加一个链接以查找代码可能会有所帮助;另外,您尝试更改的位置以及它的具体内容没有如您所期望的那样工作?一般来说,如果我不理解如何操作的话一个较大的程序可以工作,我发现从一个较小的程序开始,只关注要做的一件事(在本例中,只需打印一些内容),然后继续将其合并到一个较大的程序中是很有帮助的。。。