Chofu Programming Classroom Materials

website·Indexed 30 days ago

https://chofu-programming.netlify.app/docs

Educational materials from the Chofu Boys and Girls Invention Club Programming Classroom. The documentation provides tutorials on using micro:bit and chibi:bit with the MakeCode editor, as well as guides for p5.js and setting up React environments with Vite and D3.js.

Tokens
2.1K
Snippets
16
Records
23
Agent score
75%

What's inside Chofu Programming

  1. Overview of chibi:bit hardware features

    chibi:bit is an educational microcontroller with hardware specifications identical to the micro:bit. It features 25 LEDs, 2 button switches, an accelerometer, a magnetic sensor, and BLE (Bluetooth Low Energy) capabilities.
  2. Introduction to p5.js for graphics and visual arts

    p5.js is a programming language designed for learning, specifically used to create graphics and visual art. Developers can find a wide variety of implementation examples and samples on the official p5.js examples page.
    Visit https://p5js.org/examples/ for official samples.
  3. Overview of Chofu Youth Invention Club Programming Course Materials

    The Chofu Youth Invention Club Programming Classroom provides educational materials for different skill levels. The curriculum includes micro:bit for beginners (block-based programming) and p5.js for intermediate students (visual art using JavaScript).
  4. Choose a programming editor for micro:bit

    There are two primary editors available for programming the micro:bit (and compatible devices like chibi:bit):

    1. MakeCode Editor: A block-based programming environment (similar to Scratch) that also supports text-based coding. Accessible at https://makecode.microbit.org/#lang=ja.
    2. Python Editor: A dedicated environment for writing Python code. Accessible at https://python.microbit.org/?l=ja.

    Important Caveat: While MakeCode also allows writing Python code, the syntax and implementation differ from the dedicated Python Editor. Ensure you use the correct editor for your specific project requirements.

  5. Display random numbers on a micro:bit

    Use the MakeCode editor to generate a random number between 0 and 10 and display it on the micro:bit's LED screen. The number will change each time the program is executed.
    // Use the 'pick random 0 to 10' block
    // and pass it to the 'show number' block
  6. Implement a basic D3 line plot in React

    Create a data-driven line plot by combining React's state management with D3's scaling and line generators. The following example demonstrates how to map an array of numbers to an SVG path and a series of circles.
    // src/LinePlot.jsx
    import * as d3 from "d3";
    
    export default function LinePlot({
      data,
      width = 640,
      height = 400,
      marginTop = 20,
      marginRight = 20,
      marginBottom = 20,
      marginLeft = 20,
    }) {
      const x = d3.scaleLinear(
        [0, data.length - 1],
        [marginLeft, width - marginRight],
      );
      const y = d3.scaleLinear(d3.extent(data), [height - marginBottom, marginTop]);
      const line = d3.line((d, i) => x(i), y);
      
      return (
        <svg width={width} height={height}>
          <path
            fill="none"
            stroke="currentColor"
            strokeWidth="1.5"
            d={line(data)}
          />
          <g fill="white" stroke="currentColor" strokeWidth="1.5">
            {data.map((d, i) => (
              <circle key={i} cx={x(i)} cy={y(d)} r="2.5" />
            ))}
          </g>
        </svg>
      );
    }

    // src/App.jsx import * as d3 from "d3"; import { useState } from "react"; import LinePlot from "./LinePlot";

    export default function App() { const [data, setData] = useState(() => d3.ticks(-2, 2, 200).map(Math.sin));

    function onMouseMove(event) { const [x, y] = d3.pointer(event); setData(data.slice(-200).concat(Math.atan2(x, y))); }

    return ( <div onMouseMove={onMouseMove}> <LinePlot data={data} /> </div> ); }

  7. Initialize a React project using Vite

    Use Vite to quickly scaffold a React project. Vite is a high-performance build tool that allows for faster development cycles compared to traditional tools.
    # Create a new React project using the react template
    npm create vite@latest my-d3-app -- --template react
    
    # Navigate into the project directory
    cd my-d3-app
    
    # Install dependencies
    npm install
    
    # Start the development server
    npm run dev
  8. Create visual art with p5.js for intermediate learners

    Intermediate-level course focusing on creating visual art using p5.js (JavaScript). Note: This material is currently under construction.
  9. Programming chibi:bit with micro:bit tools

    Because the Chibibit IDE is no longer supported in browsers, users should use the micro:bit block editor to program the chibi:bit. Note that while button and LED operations are confirmed to work, sensors (such as the accelerometer) and BLE (Bluetooth) functionality may not work when using the micro:bit editor.
    Use the micro:bit block editor instead of the Chibibit IDE.