Giter Club home page Giter Club logo

pxt-chibitronics's Introduction

chibitronics target for PXT

Build Status Community Discord

This target allow to program a Chibi Chip using PXT (Microsoft Programming Experience Toolkit).

Local server

The local server allows to run the editor and the documentation from your computer.

Setup

The following commands are a 1-time setup after synching the repo on your machine.

git clone https://github.com/microsoft/pxt-chibitronics
cd pxt-chibitronics
  • install the PXT command line (add sudo for Mac/Linux shells).
npm install -g pxt
  • install the dependencies
npm install
  • install platformio command line:
python2 -m pip install -U platformio
  • install the ltc platform:
platformio platform install https://github.com/xobs/platformio-ltc

Running

Run this command to open a local web server (add sudo for Mac/Linux shells)

pxt serve

If the local server opens in the wrong browser, make sure to copy the URL containing the local token. Otherwise, the editor will not be able to load the projects.

If you need modify the .cpp files, turn on yotta compilation with the -yt flag (add sudo for Mac/Linux shells):

pxt serve -yt

Updates

To update your PXT version and make sure you're running the latest tools, run (add sudo for Mac/Linux shells)

pxt update

More instructions at https://github.com/Microsoft/pxt#running-a-target-from-localhost

pxt-chibitronics's People

Contributors

abchatra avatar audreyctseng avatar bunnie avatar guillaumejenkins avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar microsoftsam avatar mmoskal avatar msftgits avatar pelikhan avatar riknoll avatar samelhusseini avatar veler avatar xobs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pxt-chibitronics's Issues

Download information dialog box

Remind users that the board needs to be Reset (in 'Programming mode') to be flashed โ€“ ideally a .gif animation showing someone pressing the Reset button and the light turning Red.

Make the Upload button disabled while uploading

Disable the Upload button while a program upload is occurring.
Also, why do we call this "Upload" instead of "Download"? Why is this different from all our other targets? Unless there's a good reason, I'd like to stay consistent with our nomenclature.

need to have pins to be 0-based

This code does not work because pin D0 has enum value 160:

for (let index = 0; index <= 5; index++) {
    if (0 < sensing.pressed(index)) {
        rgb.setColor(Colors.Red)
    }
    loops.pause(300)
    rgb.setColor(Colors.Black)
}

You need this instead:

for (let index = 0; index <= 5; index++) {
    if (0 < sensing.pressed(DigitalPin.D0 + index)) {
        rgb.setColor(Colors.Red)
    }
    loops.pause(300)
    rgb.setColor(Colors.Black)
}

Firefox for Android doesn't show blocks area

Firefox for Android doesn't show any blocks, nor will it show the simulator. It's possible to load examples, but nothing actually happens. Selecting "Play" just causes a spinning box.

Use MP3 for IE11

The audio modulator defaults to .wav, because it is low-power and cross-platform.

However, IE11 does not support .wav, and instead must use MP3.

If you specify audioFormat='mp3' on IE11, the audio modulator will gain IE11 compatibility.

Create projects and tutorials from the LTC book

From our chat with Jie over the Makerfaire weekend, we discussed converting some of the projects in the LTC book to MakeCode. Have a first class experience for projects in the editor including tutorials and side by side content with code.

Pin D0 does not work in the simulator

Pin D0 doesn't function at all, while all other pins work.

Example code:

loops.forever(() => {
    lights.digitalWritePinOn(DigitalPin.D0)
    loops.pause(100)
    lights.digitalWritePinOff(DigitalPin.D0)
    loops.pause(100)
})

Switch to modulationVersion 2

The audio modulator supports a parameter, currently called modulationVersion, that defines the version of baud striping used by the playback function.

Version 2 is much better at DC-balancing the output than Version 1, which results in the board successfully programming the first time more often.

Please change modulationVersion to 2 inside editor/extension.ts

Enable RGB LED light (compilation)

The RGB LED is set by a call to ledShow(). It takes a struct {g, r, b} and writes the values out the RGB LED. It supports a chain of multiple lights, and in fact we will have a SKU that is a small strip of LEDs.

Here is a function that sets the one LED. You can increase the size of "struct pixels[]" to account for more LEDs wired up, but for now lets stick with just one.

#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))

struct pixels {
uint8_t g;
uint8_t r;
uint8_t b;
} attribute((packed));

void set_led(int r, int g, int b) {
struct pixels pixels[1];
unsigned int i;

for (i = 0; i < array_size(pixels); i++) {
    pixels[i].r = r;
    pixels[i].g = g;
    pixels[i].b = b;
}

Convert some of the Arduino examples into MakeCode

Basics:

  • Blink
  • Fade
  • Push On Push Off Switch

Effects:

  • Craft Effects
  • Default Code- Light Cascade
  • Button Cascade

Chibi Scope:

  • Hello World
  • Position Text
  • Animation

RGB:

  • Simple Color
  • Rainbow Cycle
  • Press For Color
  • Sensor To Color
  • Fade Color
  • Fade Color Hsv
  • Cascading Colors

Sensors:

  • Light Sensor

Custom animation blocks

Twinkle, Fade, and Heartbeat animation blocks:

#include "Arduino.h"
#include "ChibiOS.h"

enum effects {
  NONE = 0,
  BLINK = 1,
  HEARTBEAT = 2,
  TWINKLE = 3,
};

struct effects_thread_arg {
  uint8_t effect;
  uint8_t tempo;
  uint8_t pin;
};

static thread_t *light_threads[6];
static effects_thread_arg port[6];

///////////// PICK YOUR EFFECT AND TEMPO HERE
///////////// choose one of NONE, BLINK, HEARTBEAT, TWINKLE
///////////// and a tempo (generally a higher number makes it go faster)

void configure_effects() {
  port[0].effect = HEARTBEAT;
  port[1].effect = HEARTBEAT;
  port[2].effect = NONE;
  port[3].effect = TWINKLE;
  port[4].effect = TWINKLE;
  port[5].effect = BLINK;

  port[0].tempo = 1;
  port[1].tempo = 12;
  port[2].tempo = 0;
  port[3].tempo = 5;
  port[4].tempo = 2;
  port[5].tempo = 4;
}

  
static int fade_to(int current, int target, int rate, int pin, int pause) {
  while( abs(current - target) > rate ) {
    analogWrite(pin, current);
    current = current + ((target - current) > 0 ? rate : - rate);
    delay(pause);
  }
  return current;
}

static void fade_effect(struct effects_thread_arg *cfg) {
  fade_to( 0, 255, cfg->tempo, cfg->pin, 7 );
  fade_to( 255, 0, cfg->tempo, cfg->pin, 7 );
}

static void blink_effect(struct effects_thread_arg *cfg) {
  fade_to( 0, 255, cfg->tempo, cfg->pin, 7 );
  fade_to( 255, 0, cfg->tempo, cfg->pin, 7 );
}

static void twinkle_effect(struct effects_thread_arg *cfg) {
  int current = 128;
  while(1) {
    current = fade_to(current, random(0, 255), cfg->tempo, cfg->pin, 3);
  }
}

static void heartbeat_effect(struct effects_thread_arg *cfg) {
  int current = 0;
  if( cfg->tempo > 12 )
    cfg->tempo = 12;
  
  current = fade_to(current, 0xc0, 2, cfg->pin, 1);
  current = fade_to(current, 0x4, 2, cfg->pin, 1);
  delay(80); // fastest rate
  delay( (13 - cfg->tempo) * 15 );
  //delay(180);
  current = fade_to(current, 0xff, 2, cfg->pin, 1);
  current = fade_to(current, 0x00, 2, cfg->pin, 1);
  delay(214); // fastest rate
  delay( (13 - cfg->tempo) * 37 );
  //delay(420);
}

static void effects_thread(void *arg) {
  struct effects_thread_arg *cfg = (struct effects_thread_arg *)arg;
  while (1) {
    switch (cfg->effect) {
      case NONE: exitThread(0); return;
      case BLINK: blink_effect(cfg); break;
      case HEARTBEAT: heartbeat_effect(cfg); break;
      case TWINKLE: twinkle_effect(cfg); break;
      default: exitThread(0); return;
    }
  }
}

static thread_t *createThreadFromHeap(size_t size, tprio_t prio,
                                      tfunc_t pf, void *arg) {
  thread_t *thr = (thread_t *)malloc(THD_WORKING_AREA_SIZE(size));
  createThread((void *)thr, THD_WORKING_AREA_SIZE(size), prio, pf, arg);

  /* Mark thr->p_flags as CH_FLAG_MODE_HEAP, so ChibiOS will call free()
   * on the memory after it exits.
   */
  ((uint8_t *)thr)[0x1d] = 1;
  return thr;
}

void setup(void) {
  int i;
  
  configure_effects();

  for (i = 0; i < 6; i++) {
    port[i].pin = i;
    pinMode(port[i].pin, OUTPUT);
    digitalWrite(port[i].pin, LOW);
    if (port[i].effect == NONE)
      continue;
    light_threads[i] = createThreadFromHeap(32,
                                           20,
                                           effects_thread,
                                           &port[i]);
  }
}

void loop(void) {
  exitThread(0);
}

Importing a .hex file does not work

Expectation :

When selecting a previously saved .hex file into the Import modal, or drag-drop the file into the editor, the project must be loaded.

Actual result :

The project is not loaded and a "This .hex file doesn't contain source" message appear in the web browser console.

Pin drop-down menu

The pin selector drop-down menu is not touch friendly. Suggest to change this to a grid layout.
pinmenu

simulator bug: pin can transition from 0->1 but not 1->0

Run this program and click on a pin. See it transition from 0->1. However, clicking the same pin doesn't transition from 1->0:

for (let index = 0; index <= 5; index++) {
    if (0 < sensing.pressed(index)) {
    	
    }
    loops.pause(100)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.