Adafruit Industries Circuit Playground Simple Simon Manual

Advertisement

Quick Links

Circuit Playground Simple Simon
Created by Carter Nelson
Last updated on 2018-08-22 03:58:37 PM UTC

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Circuit Playground Simple Simon and is the answer not in the manual?

Questions and answers

Summary of Contents for Adafruit Industries Circuit Playground Simple Simon

  • Page 1 Circuit Playground Simple Simon Created by Carter Nelson Last updated on 2018-08-22 03:58:37 PM UTC...
  • Page 2: Table Of Contents

    Code Walk Through chooseSkillLevel() newGame() indicateButton() showSequence() getButtonPress() gameLost() gameWon() setup() loop() The Structure of struct 2D Point Example The Simple Simon "button" So Why Didn't You Just Create a simonButton Class? CircuitPython Version © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 2 of 17...
  • Page 3: Overview

    Before Starting If you are new to the Circuit Playground, you may want to first read these overview guides. Circuit Playground Classic Overview (https://adafru.it/ncG) Lesson #0 (https://adafru.it/rb4) Circuit Playground Express Overview (https://adafru.it/AgP) © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 3 of 17...
  • Page 4: Playing The Game

    4 -> N=31 The game is played by repeating the sequence of lights shown using the associated touch pads. There are four different sections of lights, each with its own color and tone. © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 4 of 17...
  • Page 5: Winning

    Playing Again Simply press RESET to start a new game. Example Game Play The video below demonstrates selecting a skill level, starting a new game, general game play, and successfully completing the sequence. © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 5 of 17...
  • Page 6: Code Walk Through

    4: sequenceLength = 31; break; // Populate the game sequence for (int i=0; i<sequenceLength; i++) { simonSequence[i] = random(4); // We start with the first step in the sequence currentStep = 1; © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 6 of 17...
  • Page 7: Indicatebutton()

    The game sequence is played back up to the current game play location. The duration of the tone is set in the statement based on the current location. This sets the play back speed of the sequence. Then, the sequence is played back up to its current location. getButtonPress() © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 7 of 17...
  • Page 8: Gamelost()

    // And just sit here until reset while (true) {} The "button" that is passed in via is shown, the sad tone is played, and the game ends at an infinite loop. gameWon() © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 8 of 17...
  • Page 9: Setup()

    { // Initialize the Circuit Playground CircuitPlayground.begin(); // Set play level skillLevel = 1; CircuitPlayground.clearPixels(); CircuitPlayground.setPixelColor(0, 0xFFFFFF); chooseSkillLevel(); // Sowing the seeds of random randomSeed(millis()); // Create game newGame(); © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 9 of 17...
  • Page 10: Loop()

    . The button value is then compared to the NO_BUTTON current sequence value. If it's correct, the game continues. If it's wrong, the game is over. Once the step values exceeds the game sequence length, the game is won. © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 10 of 17...
  • Page 11: The Structure Of Struct

    This is where a struct would help out. Instead of two separate variable, we create a single struct to represent the 2D point, and put the variables in there. struct point { float x; float y; © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 11 of 17...
  • Page 12: The Simple Simon "Button

    NeoPixels, and the frequency of the tone for the button. We have more than one "button", so we create an array of them and initialize their values: © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 12 of 17...
  • Page 13: So Why Didn't You Just Create A Simonbutton Class

    Hopefully that makes some sense and you see how it is useful. If not, meh, just have fun playing the game..for now. So Why Didn't You Just Create a simonButton Class? Just trying to keep it simple. But this is totally doable, since Arduino uses C++ under the hood. © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 13 of 17...
  • Page 14: Circuitpython Version

    = skill_level if skill_level < 5 else 1 # Indicate current skill level cpx.pixels.fill(0) for p in range(skill_level): cpx.pixels[p] = 0xFFFFFF time.sleep(DEBOUNCE) return skill_level def new_game(skill_level): # Seed the random function with noise a4 = AnalogIn(board.A4) a5 = AnalogIn(board.A5) © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 14 of 17...
  • Page 15 == 7: return cpx.touch_A7 def get_button_press(): # Loop over all the buttons for button in SIMON_BUTTONS.values(): # Loop over each pad for pad in button['pads']: if cap_map(pad): indicate_button(button, DEBOUNCE) return button return None © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 15 of 17...
  • Page 16 = 0xFFFFFF skill_level = choose_skill_level() sequence = new_game(skill_level) current_step = 1 #Loop forever while True: # Show sequence up to current step show_sequence(sequence, current_step) # Read player button presses for step in range(current_step): © Adafruit Industries https://learn.adafruit.com/circuit-playground-simple-simon Page 16 of 17...
  • Page 17 = get_button_press() if not guess == SIMON_BUTTONS[sequence[step]]: game_lost(sequence[step]) # Advance the game forward current_step += 1 if current_step > len(sequence): game_won() # Small delay before continuing time.sleep(SEQUENCE_DELAY) © Adafruit Industries Last Updated: 2018-08-22 03:58:32 PM UTC Page 17 of 17...

Table of Contents