※和文はページ下部にあります
Previous sections:
- Setup + LED: https://tinyurl.com/picoruby-2025
- Microphone: https://tinyurl.com/picoruby-mic
- Buzzer: https://tinyurl.com/picoruby-buzzer
- Useful gems: https://tinyurl.com/picoruby-gems
| #!/usr/bin/env ruby | |
| require 'fileutils' | |
| DEFAULT_DEVICE = '/dev/ttyUSB0' | |
| DEFAULT_BAUDRATE = '115200' | |
| if ARGV.include?('--help') || ARGV.include?('-h') | |
| puts <<~HELP | |
| This script connects to a serial device using 'screen' and automatically |
※和文はページ下部にあります
Previous sections:
※和文はページ下部にあります
Previous sections:
So far we've learned the fundamental peripherals: GPIO, ADC, and PWM. These are the building blocks of all microcontroller programming. Now let's explore how PicoRuby's gem system makes working with complex sensors much easier!
※和文はページ下部にあります
Previous sections:
In this section, we'll learn about PWM (Pulse Width Modulation) - a powerful technique that allows us to simulate analog signals using digital outputs. We'll use PWM to create sounds with a buzzer and control LED brightness smoothly.
※和文はページ下部にあります
Previous sections:
In this section, we'll learn about analog-to-digital conversion (ADC) and explore how to read analog sensors. We'll use a microphone to detect sound levels and also explore the RP2350's built-in temperature sensor.
※和文はページ下部にあります
Before starting, please check the following resources:
R2P2-PICORUBY-PICO2_W-*.uf2 (PICO2_W is the point)(Also read Trouble Shoot)
If your laptop is configured to prohibit writing to USB memory devices, likely due to your company's security policy, it will not function in the workshop😣
| require "adc" | |
| require "mouse" | |
| kbd = Keyboard.new | |
| kbd.init_direct_pins( [8] ) | |
| kbd.add_layer :default, %i(BOOTSEL) | |
| kbd.define_mode_key :BOOTSEL, [ Proc.new { kbd.bootsel! }, nil, 300, nil ] |
| require "spi" | |
| require "mouse" | |
| require "consumer_key" | |
| class SPI | |
| def pmw3360dm_write(*values) | |
| GPIO.write_at(21, 0) | |
| write(*values) | |
| Machine.delay_us 20 | |
| GPIO.write_at(21, 1) |
| # | |
| # Pin assignment: | |
| # switch matrix: | |
| # row: 1, 2, 3, 4 | |
| # col: 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 | |
| # RGBLED: 0 | |
| # I2C0: trackball and RTC | |
| # sda_pin: 20 | |
| # scl_pin: 21 | |
| # SPI1: |