Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Flojoy snake demo #149

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open

Flojoy snake demo #149

wants to merge 31 commits into from

Conversation

izi-on
Copy link
Contributor

@izi-on izi-on commented Jul 4, 2023

Description

GAMEPAD node:
The gamepad node uses the hidapi package to read input devices. It scans for a device that has the name "gamepad" in it,
and then it listens to inputs from it. The inputs are described by a list of booleans that is set on the "y" field of the DataContainer of type ordered_pair.

Suggestions: add new type "gamepad input"?

SNAKE_GAME node:
The snake game node takes as an input an ordered_pair DataContainer and reads the "y" field for the list of booleans.
It grabs its previous game state from Small Memory, then with the new inputs calculates its new state and writes it again to Small Memory. The node returns a DataContainer of type 'image' that corresponds to snake game matrix.

LED_MATRIX node:
The LED matrix node takes as an input a DataContainer of type image. Using the following Arduino script:

#include <Adafruit_NeoPixel.h>

#define PIN        6 // LED Strip connected on Pin 6
#define NUMPIXELS 484 // Number of LEDs in your strip

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin(); 
  Serial.begin(115200); 
  pixels.setPixelColor(0, pixels.Color(255,0,0));
  pixels.show();
  // Serial.setTimeout(0.1);
}

void loop() {
  if (Serial.available() > 0) {
    pixels.clear();
    for (int i = 0; i < 484; i++) {
      int ledNum = Serial.parseInt(); 
      int red = Serial.parseInt(); 
      int green = Serial.parseInt(); 
      int blue = Serial.parseInt(); 
      pixels.setPixelColor(ledNum, pixels.Color(red, green, blue));
    }
    pixels.show();
    while(Serial.available() > 0) {
      char t = Serial.read();
    }
  }
}

It communicates via serial to the Arduino that has a WS2812B LED Matrix connected to the 6th digital pin.

Styleguide

  • My node adheres to the styleguide for Flojoy nodes

Docs

  • I've submitted a PR for a documentation page for the new node(s) that contains usage examples (see docs.flojoy.io)

Testing

  • This PR includes a unit test (example here and/or ideally a screenshot of the node's output on an example app.

@itsjoeoui itsjoeoui changed the base branch from main to develop July 13, 2023 14:52
@smahmed776 smahmed776 changed the base branch from develop to main July 20, 2023 19:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants