Quero colocar uma sequencia predefinida e remover a repetição

//Criação de Aline Carmona Doria para 2a1

#define do3 130
#define dox3 138
#define re3 146
#define rex3 155
#define mi3 164
#define fa3 174
#define fax3 185
#define sol3 196
#define solx3 207
#define la3 220
#define lax3 233
#define si3 242

int tons[12] = {do3, re3, mi3, fa3};

int sequencia[100] = {};

int rodada_atual = 0;

int passo_atual_na_sequencia = 0;

int pinoAudio = 4;

int pinoLed[4] = {13, 12, 11, 10};

int pinoBotao[4] = {8, 7, 6, 5};

int botao_pressionado = 0;

int perdeu_o_jogo = false;

int fim_de_jogo = false;

int level[5] = {3, 4, 2, 3, 1};

int level_atual = 0;

int i = 0;

void setup(){

for (int i = 0; i<= 3; i++){
pinMode(pinoLed[i], OUTPUT);
}

for (int i = 0; i<= 3; i++){
pinMode(pinoBotao[i], INPUT);
}

pinMode(pinoAudio, OUTPUT);

int i;

}

void loop() {

if (perdeu_o_jogo) {
int sequencia[100] = {};
rodada_atual = 0;
passo_atual_na_sequencia = 0;
perdeu_o_jogo = false;
}

if (rodada_atual == 0) {
tocarSomDeInicio();
delay(500);
}

if (rodada_atual == 3){
completo();
delay(1000);
}

if (fim_de_jogo) {
int sequencia[100] = {};
rodada_atual = 0;
passo_atual_na_sequencia = 0;
fim_de_jogo = false;
}

proximaRodada();

reproduzirSequencia();

aguardarJogador();

delay(500);

}

void proximaRodada() {

int proximo_level = level[i++];

sequencia[rodada_atual++] = proximo_level;

for (i = 0; i <= level_atual; i++) {
level[i++];

}

}

void reproduzirSequencia() {

for (int i = 0; i < rodada_atual; i++) {
tone(pinoAudio, tons[sequencia[i]]);
digitalWrite(pinoLed[sequencia[i]], HIGH);
delay(500);
noTone(pinoAudio);
delay(100);
}
noTone(pinoAudio);
}

void aguardarJogador() {

for (int i = 0; i < rodada_atual; i++) {
aguardarJogada();
verificarJogada();

if (perdeu_o_jogo) {
break;
}

passo_atual_na_sequencia++;
}

passo_atual_na_sequencia = 0;
}

void aguardarJogada() {

boolean jogada_efetuada = false;

while (!jogada_efetuada) {
for (int i = 0; i <= 3; i++) {

if (digitalRead(pinoBotao[i]) == HIGH) {
botao_pressionado = i;
tone(pinoAudio, tons[i]);
digitalWrite(pinoLed[i], HIGH);
delay(300);
digitalWrite(pinoLed[i], LOW);
noTone(pinoAudio);
jogada_efetuada = true;
}
}
delay(10);
}
}

void verificarJogada() {

if (sequencia[passo_atual_na_sequencia] != botao_pressionado) {
// GAME OVER.

for (int i = 0; i <= 3; i++) {
tone(pinoAudio, tons[i]);
digitalWrite(pinoLed[i], HIGH);
delay(200);
digitalWrite(pinoLed[i], LOW);
noTone(pinoAudio);
}

tone(pinoAudio, tons[3]);
for (int i = 0; i <= 3; i++) {
digitalWrite(pinoLed[0], HIGH);
digitalWrite(pinoLed[1], HIGH);
digitalWrite(pinoLed[2], HIGH);
digitalWrite(pinoLed[3], HIGH);
delay(100);
digitalWrite(pinoLed[0], LOW);
digitalWrite(pinoLed[1], LOW);
digitalWrite(pinoLed[2], LOW);
digitalWrite(pinoLed[3], LOW);
delay(100);
}

noTone(pinoAudio);
perdeu_o_jogo = true;
}
}

void tocarSomDeInicio() {

tone(pinoAudio, tons[0]);
digitalWrite(pinoLed[0], HIGH);
digitalWrite(pinoLed[1], HIGH);
digitalWrite(pinoLed[2], HIGH);
digitalWrite(pinoLed[3], HIGH);
delay(500);
digitalWrite(pinoLed[0], LOW);
digitalWrite(pinoLed[1], LOW);
digitalWrite(pinoLed[2], LOW);
digitalWrite(pinoLed[3], LOW);
delay(500);
noTone(pinoAudio);
}

void completo(){
tone(pinoAudio, tons[0]);
digitalWrite(pinoLed[0], HIGH);
digitalWrite(pinoLed[1], HIGH);
digitalWrite(pinoLed[2], HIGH);
digitalWrite(pinoLed[3], HIGH);
delay(500);
digitalWrite(pinoLed[0], LOW);
digitalWrite(pinoLed[1], LOW);
digitalWrite(pinoLed[2], LOW);
digitalWrite(pinoLed[3], LOW);
delay(500);
noTone(pinoAudio);
delay(1000);

fim_de_jogo = true;
}

Können Sie uns mehr Informationen darüber geben, was Sie versuchen zu tun? Erhalten Sie eine Fehlermeldung oder erhalten Sie nicht das gewünschte Ergebnis?

Hat dies etwas mit der OpenAI API zu tun?

Based on the code, it seems that the programming language is Arduino, using the C/C++ syntax. I believe she tried to send this question to ChatGPT but due to the recent shortages she posted here or of confusion or purposely trying to find some help. I found some help to post here, and I can comment that she may not repeat such a procedure in her own language - this is the last time.

My suggestion for the forum administrators is: to maintain an updated discussion with the Status and to keep it at the top of the Latest and the Top lists discussion. A lot of people today, mainly non-native English ones, had complained about it. It has been difficult to find some information on the OpenAI site mainly after the pages had changed, for example, the Dashboard. People are really confused, they expect too much - patience is advised - despite I think I was not worthy of such a blessing…

1 Like

Verzeihen Sie mir Fehler, ich benutze den Übersetzer.

Dies ist ein Code für Arduino, Sie möchten ein Klavier bauen, das die Taste beleuchtet, es leuchtet, bis es gespielt wird, entsprechend der Reihenfolge der Musik, und wenn der Spieler alles vervollständigt, spielt die komplette Musik.

Das Programm funktioniert nicht wie erwartet.

First forgive me for any mistakes I’m using the translator.

I’m in need of help and I’ve exhausted all my resources near me, so my teacher referred me to this chat.

Acho que seu professor se referia ao ChatGPT que é a Inteligência Artificial que trata de qualquer assunto mas é muito usado por desenvolvedores. E o bichinho é relativamente bom nisso. Tem conta gratuita para ele basta entrar com seu email. E evitar usar no horário de pico das Costas Leste e Oeste Americanas. Aqui é o fórum dos Usuários do ChatGpt e os APIs da OpenAI - na sua maior parte para reclamação ou busca de ajuda para o uso dos serviços da OpenAI. Você vai ver muita gente falando que é fórum de desenvolvedores interessado em IA - mas isso não é “muito” verdade. Eu vou postar aqui a solução que o ChatGPT me deu, mas evite fazer isso aqui no fórum. Abra sua conta gratuita no ChatGPT e pode conversar com o IA à vontade sobre suas dúvidas e assuntos técnicos que ninguém perturbar - é um chat um pra um. Vamos agora à sua dúvida:

thank you very much.

I worked several hours before my teacher suggested me this chat you commented on, I entered it and created the account but I ended up here, I don’t know how, I was very tired I didn’t notice that it wasn’t the same place.

Traduzi a resposta do ChatGPT de Inglês para Português no GT - mas ele escreve em Português se você quiser - não sei qual o nível dele porque só converso com ele em Inglês. Eu chamo de “ele” (apesar de ser uma “IA”) por o chamo de Geppetto. O fórum aqui não me deixa colocar mais de 2 respostas seguidas se eu não receber uma resposta - então tive que colocar tudo junto.

1a parte:
Para remover duplicidades de uma sequência, pode-se usar um loop para iterar sobre cada elemento e usar outro loop aninhado para comparar o elemento atual com todos os elementos seguintes. Se um elemento duplicado for encontrado, ele pode ser removido deslocando todos os elementos a seguir para a esquerda.

2a parte:
a função ‘removeDuplicates’ usa uma matriz de inteiros ‘arr’ e seu comprimento ‘len’ como argumentos. Ela itera sobre cada elemento da matriz e o compara com todos os elementos a seguir usando um loop aninhado. Se um elemento duplicado for encontrado, ele desloca todos os elementos seguintes para a esquerda em uma posição e diminui o comprimento da matriz. O índice ‘j’ também é ajustado para evitar pular o próximo elemento. Por fim, a função retorna o comprimento da matriz sem duplicidades.

3a parte:
Na função ‘loop’, a função ‘removeDuplicates’ é chamada com a matriz de sequência e seu comprimento como argumentos. A função então imprime a sequência sem duplicidades usando um ‘loop for’. O programa então entra em um loop infinito para evitar que seja executado novamente.

  1. parte: (Exemplo)
    Aqui está um exemplo de implementação de uma função para remover duplicatas de um array inteiro no Arduino: Código C++

#define LENGTH 10 // o comprimento da sequência
int sequence[LENGTH] = {1, 2, 3, 4, 5, 4, 3, 2, 1, 6}; // a sequência com duplicidades
void removeDuplicates(int arr, int len) {
for (int i = 0; i < len; i++) {
for (int j = i + 1; j < len; j++) {
if ( arr[i] == arr[j]) { // desloca todos os elementos seguintes para a esquerda
for (int k = j; k < len - 1; k++) {
arr[k] = arr[k + 1];
}
len–; // decrementa o tamanho do array
j–; // ajuste o índice para evitar pular o próximo elemento
}
}
}
}

void setup() {
// configure o código AQUI
}

void loop() {
removeDuplicates(sequence, LENGTH); // remove duplicidades da sequência

// imprime a sequência sem duplicidades
for (int i = 0; i < LENGTH; i++) {
	Serial.println(sequence[i]);
}
while (true) {
	// loop indefinidamente
}

}

In fact, the duplicate I mentioned refers to the repetition of the sequence and not the door. Like that Genius memory game, (I don’t know if you guys had it) it repeats a sequence before adding a new button to press and that’s what I don’t want my program to do.

I managed to remove the repetition of the sequence (I think), but I couldn’t predetermine the order that the logic gates should trigger.

I updated the code I uploaded here, trying to find the answer while it wasn’t answered. I’ll send it here so you can have a look.

//Criação de Aline Carmona Doria para 2a1

#define do3 130
#define dox3 138
#define re3 146
#define rex3 155
#define mi3 164
#define fa3 174
#define fax3 185
#define sol3 196
#define solx3 207
#define la3 220
#define lax3 233
#define si3 242

int tons[12] = {do3, re3, mi3, fa3};

int rodada_atual = 0;

int passo_atual_na_sequencia = 0;

int botao_pressionado = 0;

int perdeu_o_jogo = false;

int fim_de_jogo = false;

int pinoAudio = 4;

int pinoLed[4] = {13, 12, 11, 10};

int pinoBotao[4] = {8, 7, 6, 5};

int level[5] = {2>>3>>1>>2>>0};

int level_atual = 0;

int i = 0;

void setup(){

for (int i = 0; i<= 3; i++){
pinMode(pinoLed[i], OUTPUT);
}

for (int i = 0; i<= 3; i++){
pinMode(pinoBotao[i], INPUT);
}

pinMode(pinoAudio, OUTPUT);

int rodada_atual;

int i;

}

void loop() {

if (perdeu_o_jogo) {
rodada_atual = 0;
passo_atual_na_sequencia = 0;
perdeu_o_jogo = false;
}

if (rodada_atual == 0) {
tocarSomDeInicio();
delay(500);
}

if (rodada_atual == 5){
completo();
delay(1000);
}

if (fim_de_jogo) {
rodada_atual = 0;
passo_atual_na_sequencia = 0;
fim_de_jogo = false;
}

proximaRodada();

reproduzirSequencia();

aguardarJogador();

delay(500);

}

void proximaRodada(){

int proximo_level = level[i++];

for (i = 0; i <= level_atual; i++) {
level[i++];

}

for (rodada_atual=0; rodada_atual<=proximo_level; rodada_atual++){

}

}

void reproduzirSequencia() {

for (int i = 0; i < rodada_atual; i++) {
tone(pinoAudio, tons[i]);
digitalWrite(pinoLed[i], HIGH);
delay(500);
noTone(pinoAudio);
delay(100);
}
noTone(pinoAudio);
}

void aguardarJogador() {

for (int i = 0; i < rodada_atual; i++) {
aguardarJogada();
verificarJogada();

if (perdeu_o_jogo) {
break;
}

passo_atual_na_sequencia++;
}

passo_atual_na_sequencia = 0;
}

void aguardarJogada() {

boolean jogada_efetuada = false;

while (!jogada_efetuada) {
for (int i = 0; i <= 3; i++) {

if (digitalRead(pinoBotao[i]) == HIGH) {
botao_pressionado = i;
tone(pinoAudio, tons[i]);
digitalWrite(pinoLed[i], HIGH);
delay(300);
digitalWrite(pinoLed[i], LOW);
noTone(pinoAudio);
jogada_efetuada = true;
}
}
delay(10);
}
}

void verificarJogada() {

if (passo_atual_na_sequencia != botao_pressionado) {
// GAME OVER.

for (int i = 0; i <= 3; i++) {
tone(pinoAudio, tons[i]);
digitalWrite(pinoLed[i], HIGH);
delay(200);
digitalWrite(pinoLed[i], LOW);
noTone(pinoAudio);
}

tone(pinoAudio, tons[3]);
for (int i = 0; i <= 3; i++) {
digitalWrite(pinoLed[0], HIGH);
digitalWrite(pinoLed[1], HIGH);
digitalWrite(pinoLed[2], HIGH);
digitalWrite(pinoLed[3], HIGH);
delay(100);
digitalWrite(pinoLed[0], LOW);
digitalWrite(pinoLed[1], LOW);
digitalWrite(pinoLed[2], LOW);
digitalWrite(pinoLed[3], LOW);
delay(100);
}

noTone(pinoAudio);
perdeu_o_jogo = true;
}
}

void tocarSomDeInicio() {

tone(pinoAudio, tons[0]);
digitalWrite(pinoLed[0], HIGH);
digitalWrite(pinoLed[1], HIGH);
digitalWrite(pinoLed[2], HIGH);
digitalWrite(pinoLed[3], HIGH);
delay(500);
digitalWrite(pinoLed[0], LOW);
digitalWrite(pinoLed[1], LOW);
digitalWrite(pinoLed[2], LOW);
digitalWrite(pinoLed[3], LOW);
delay(500);
noTone(pinoAudio);
}

void completo(){

for(int j=0; j<5; j++){

digitalWrite(pinoLed[0], HIGH);
delay(200);
digitalWrite(pinoLed[0], LOW);
delay(500);

digitalWrite(pinoLed[1], HIGH);
delay(200);
digitalWrite(pinoLed[1], LOW);
delay(500);

digitalWrite(pinoLed[2], HIGH);
delay(200);
digitalWrite(pinoLed[2], LOW);
delay(500);

digitalWrite(pinoLed[3], HIGH);
delay(200);
digitalWrite(pinoLed[3], LOW);
delay(500);

digitalWrite(pinoLed[0], HIGH);
digitalWrite(pinoLed[1], HIGH);
digitalWrite(pinoLed[2], HIGH);
digitalWrite(pinoLed[3], HIGH);
delay(200);
digitalWrite(pinoLed[0], LOW);
digitalWrite(pinoLed[1], LOW);
digitalWrite(pinoLed[2], LOW);
digitalWrite(pinoLed[3], LOW);
delay(200);

digitalWrite(pinoLed[0], HIGH);
digitalWrite(pinoLed[1], HIGH);
digitalWrite(pinoLed[2], HIGH);
digitalWrite(pinoLed[3], HIGH);
delay(200);
digitalWrite(pinoLed[0], LOW);
digitalWrite(pinoLed[1], LOW);
digitalWrite(pinoLed[2], LOW);
digitalWrite(pinoLed[3], LOW);
delay(200);
}

fim_de_jogo = true;
}

Pode falar em Português por favor. Até onde sei o fórum acompanha o ideal da OpenAI e do projeto GPT - sem discriminação, sem antropomorfismo. Agora, tem gente que não gosta… sabe como é… aguarde um pouco por favor. Responda essa aqui para liberar a nova resposta

Ok vou falar em português então.

Confirma isso:
Like that Genius memory game, (I don’t know if you guys had it) it repeats a sequence before adding a new button to press and that’s what I DON’T WANT MY PROGRAM TO DO.

Isso mesmo, e não quero que ele repita tudo antes de adicionar a proxima tecla.

Sabe o piano tiles que vai mostrando o que apertar de acordo com a musica? É assim que eu quero que fique.

Primeiro - só para evitar alguma confusão:
Percebi que tem duas variáveis com o mesmo nome ‘int i’ no ‘global scope’ e ‘void setup()’. Sugiro que remova um deles para evitar confusão. Talvez não seja a causa do não funcionamento, mas é bom limpar o código.

Segundo: (você tem que responder para liberar minhas respostas aqui - ou escolha outro local onde podemos fazer isso)
A diferença entre as duas variações é que:
A primeira sintaxe declara uma nova variável dentro do escopo do loop:

Isso foi feito em todas as funções exceto uma!!!

A segunda sintaxe usa uma variável existente que deve ser declarada anteriormente no programa:

a única exceção que encontrei até agora (sem simulador de Arduino) - no ‘proximaRodada’
void proximaRodada(){
int proximo_level = level[i++];
for (i = 0; i <= level_atual; i++) {
level[i++];
}
for (rodada_atual=0; rodada_atual<=proximo_level; rodada_atual++){
}
}

É isso mesmo?

podemos falar pelo instagran ou e-mail se for mais facil.

se sua pergunta foi se esse codigo foi oq eu escrevi então eu acho que sim

vai no meu perfil - manda uma messagem privada com email - sem Instagram.

não sei como mandar essa mensagem privada, ainda não sei navegar aqui

Clica no meu avatar (o Dilbert) aparece um box com botão “Message” - mensagem vai ser para mim - prefiro não fazer no fórum, antes que recebamos alguma reclamação e acabemos fora daqui

1 Like

Conseguiu? acho que encontrei uma variável que não atualiza no seu programa - fiz diversos comentários na sua listagem - e você precisa responder aqui se quiser liberar uma nova
resposta minha

1 Like