Hello,
I am making a Mastermind game in Arduino using a Tinkerkit.
I am using multiple sensors to make it happen.
I am kinda stuck now. I managed to choose the colors using a potentiometer.
By using a 8 LED neopixel strip i want to display the colors.
The first 4 LEDs are for picking the color you want. The last 4 LEDs are for feedback from those colors you pick
My question is:
How can arduino make a random color pattern for me?
How can i make the arduino give feedback to my by displaying colors on the last 4 LEDs?
(By using Green for correct place, and Red for Wrong place)
How can Arduino check the if my color selection was correct and give the feedback?
I hope someone can help my
Thanks
Down here will be the code i already have.
//Download Adafruit_NeoPixel.h here: GitHub - adafruit/Adafruit_NeoPixel: Arduino library for controlling single-wire LED pixels (NeoPixel, WS2812, etc.)
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define ledpin 6
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 8
#define Pot A4 // Hiermee maken we arduino duidelijk dat als wij sensor typen dat we die sensor bedoelen die op pin A4 zit.
#define Schuif A5 // Hiermee maken we arduino duidelijk dat als wij sensor typen dat we die sensor bedoelen die op pin A5 zit.
int potVal = 0; // Variable to store the input from the potentiometer
int potPin = A4; // Potentiometer output connected to analog pin 3
int schuifVal = 0; // Variable to store the input from the potentiometer
int schuifPin = A5; // Potentiometer output connected to analog pin A5
int kleur_led1;
int kleur_led2;
int kleur_led3;
int kleur_led4;
long kleur1, kleur2, kleur3, kleur4, kleur5, kleur6;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, ledpin, NEO_GRB + NEO_KHZ800);
int delayval = 100; // delay for 0,1 second
void setup() {
Serial.begin(9600); //Start verbinding met de pc
pixels.begin(); // This initializes the NeoPixel library.
pixels.setBrightness(20);
kleur1 = pixels.Color(225, 225, 0); //Geel
kleur2 = pixels.Color(0, 225, 0); //Groen
kleur3 = pixels.Color(0, 0, 225); //Blauw
kleur4 = pixels.Color(225, 0, 225); //Paars
kleur5 = pixels.Color(150, 150, 225); //Wit
kleur6 = pixels.Color(225, 0, 0); //Rood
}
void loop() {
schuifVal = analogRead (Schuif);
potVal = analogRead(Pot);
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
//potVal = analogRead(potPin); // read the potentiometer value at the input pin
//Serial.println(potVal);
schuifVal = analogRead(schuifPin); // read the schuifmeter value at the input pin
Serial.println(schuifVal);
Color();
}
void Color() {
//Alleen de eerste 4 leds van de strip worden van kleur veranderd door de potentiometer. De laatste 4 leds dienen voor feedback of de code goed is.
if ( schuifVal < 185) //als de schuif-potentiometer zich in het de eerste 12,5% (1/8) van de balk zich bevind, dan gaat de eerste van de 8 leds van kleur veranderen.
{
if (potVal < 170) // Lowest third of the potentiometer's range (0-170)
{
led(0, 1);
}
else if (potVal < 340) //
{
led(0, 2);
}
else if (potVal < 510) //
{
led(0, 3);
}
else if (potVal < 682) //
{
led(0, 4);
}
else if (potVal < 850) //
{
led(0, 5);
}
else if (potVal < 1024) //
{
led(0, 6);
}
}
else if (schuifVal < 370) //als de schuif-potentiometer zich in het de eerste 25% (2/8) van de balk zich bevind, dan gaat de eerste van de 8 leds van kleur veranderen.
{
if (potVal < 170) // Lowest third of the potentiometer's range (0-170)
{
led(1, 1);
}
else if (potVal < 340) //
{
led(1, 2);
}
else if (potVal < 510) //
{
led(1, 3);
}
else if (potVal < 682) //
{
led(1, 4);
}
else if (potVal < 850) //
{
led(1, 5);
}
else if (potVal < 1024) //
{
led(1, 6);
}
}
else if (schuifVal < 550) //als de schuif-potentiometer zich in het de eerste 37,5% (3/8) van de balk zich bevind, dan gaat de eerste van de 8 leds van kleur veranderen.
{
if (potVal < 170) // Lowest third of the potentiometer's range (0-170)
{
led(2, 1);
}
else if (potVal < 340) //
{
led(2, 2);
}
else if (potVal < 510) //
{
led(2, 3);
}
else if (potVal < 682) //
{
led(2, 4);
}
else if (potVal < 850) //
{
led(2, 5);
}
else if (potVal < 1024) //
{
led(2, 6);
}
}
else if (schuifVal < 740) //als de schuif-potentiometer zich in het de eerste 50% (4/8) van de balk zich bevind, dan gaat de eerste van de 8 leds van kleur veranderen.
{
if (potVal < 170) // Lowest third of the potentiometer's range (0-170)
{
led(3, 1);
}
else if (potVal < 340) //
{
led(3, 2);
}
else if (potVal < 510) //
{
led(3, 3);
}
else if (potVal < 682) //
{
led(3, 4);
}
else if (potVal < 850) //
{
led(3, 5);
}
else if (potVal < 1024) {
led(3, 6);
}
}
}
void led(int led, int kleur) {
long ledkleur;
switch (led) { //Het opslaan van de kleur in de LEDs
case 1:
kleur_led1 = kleur;
break;
case 2:
kleur_led2 = kleur;
break;
case 3:
kleur_led3 = kleur;
break;
case 4:
kleur_led4 = kleur;
break;
}
switch (kleur) {
case 1:
ledkleur = kleur1;
break;
case 2:
ledkleur = kleur2;
break;
case 3:
ledkleur = kleur3;
break;
case 4:
ledkleur = kleur4;
break;
case 5:
ledkleur = kleur5;
break;
case 6:
ledkleur = kleur6;
break;
}
pixels.setPixelColor(led, ledkleur); //
pixels.show();
}