Skip to content

Instantly share code, notes, and snippets.

View masquaremo's full-sized avatar

H.Matsumoto masquaremo

View GitHub Profile
@masquaremo
masquaremo / gpio4.rb
Last active December 11, 2015 17:38
Raspberry Pi(Raspbian)のRubyでGPIO4のLチカ(デバイスファイル使用)
#!/usr/bin/ruby
system('echo "4" > /sys/class/gpio/export')
system('echo "out" > /sys/class/gpio/gpio4/direction')
[0, 1].cycle do |sw|
system("echo #{sw} > /sys/class/gpio/gpio4/value")
sleep(0.5)
end
@masquaremo
masquaremo / gpio_c.c
Last active December 11, 2015 19:19
雑誌インターフェース 2012年12月号のGPIO制御のコードがRev1用みたいだったのでRev2用に修正。 また、GPIO4がなぜか無効になっていた(何故かはよくわからない)ので使えるようにした。
//
// How to access GPIO registers from C-code on the Raspberry-Pi
// Example program
// 15-January-2012
// Dom and Gert
//
// Access from ARM Running Linux
@masquaremo
masquaremo / pwm.c
Created January 30, 2013 12:20
Raspberry PiのPWM制御サンプル
//
// BCM2835 pwm lib
//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/mman.h>
@masquaremo
masquaremo / pwm.rb
Last active December 11, 2015 22:58
Raspberry PiのPWM制御をライブラリ化し、Rubyから使用するサンプル
require 'pwmlib'
pwm = Pwmlib
pwm.set_range(1000)
0.step(1000, 100) do |i|
sleep(1)
puts "d=#{i}"
pwm.set_duty(i)
end
@masquaremo
masquaremo / hello.rb
Created September 11, 2013 13:40
数値・文字・文字列リテラルをつかわずに、"Hello World"と標準出力に出力する。 (カッコ悪いバージョン)
one = [nil].size
two = one + one
three = two + one
four = three + one
five = four + one
six = five + one
seven = six + one
eight = seven + one
nine = eight + one
ten = nine + one
@masquaremo
masquaremo / hello2.rb
Created September 13, 2013 14:16
数値・文字・文字列リテラルをつかわずに、"Hello World"と標準出力に出力する。 (少しましなバージョン)
two = [nil, nil].size
sp = two << (two + two)
class Hello; end
class World; end
print Hello.new.class.to_s + sp.chr + World.new.class.to_s
@masquaremo
masquaremo / .gvimrc
Last active October 21, 2018 07:38
自分用gvimrc
"===================================================
" gvimrc(vim8-Win64 GUIで動確)
"===================================================
colorscheme desert " カラースキーム
set lines=50 " ウィンドウの縦幅
set columns=120 " ウィンドウの横幅
set guifont=MS_Gothic:h9 "半角文字の設定
set guifontwide=MS_Gothic:h9 "全角文字の設定
@masquaremo
masquaremo / .vimrc
Last active September 10, 2019 21:20
自分用vimrc
"===================================================
" vimrc(vim8-Win64 GUIで動確)
"===================================================
scriptencoding utf-8 "このファイルのエンコード
"---------------------------------------------------
" ファイル系
set fileencodings=utf-8,cp932 " ファイルを開いたときに自動認識するエンコード
set fenc=utf-8 "文字コードをUFT-8に設定
set nobackup " バックアップファイルを作らない
@masquaremo
masquaremo / str_num_sample.rb
Last active May 30, 2021 06:56
Rubyで文字列と数値を相互に変換するメソッドとかのまとめ
#!/usr/bin/ruby
#数値を16進数文字列に
p 65.to_s(16) #=> "41"
#数値をASCII文字に
p 65.chr #=> "A"
#文字列を16進数とみなして数値に
p "41".hex #=> 65