PSoC4 : UART + Capsense Tuner

タッチセンサの感度調整ツール「CapsenseTuner」で、I2C通信を使う例はよく見ます。サンプルもI2C通信のみしかありません。でもUARTにも対応していて、CapsenseTunerでも接続先をUARTに設定することができます。サイトにも、できるよと情報があるのですが、実際のプログラムやプロジェクトの細かい設定までは、説明が見つかりません。

“PSoC4 : UART + Capsense Tuner” の続きを読む

PSoC4 : タッチセンサの反応をよくする

PSoC4の開発環境「ModusToolBox」で、タッチセンサとシリアル通信をするメモです。使用するPSoCは「CY8C4025AXI-S412」です。タッチセンサに使うクロック周波数を上げると反応速度が速くなったり、電源電圧を少し低くすると安定したり、SmartSenseのキャパシタの値を変更して、個別に調整できたりしました。

“PSoC4 : タッチセンサの反応をよくする” の続きを読む

PSoC4 : CapSense & UART(文字化けないポイント)

PSoC4の開発環境「ModusToolBox」で、タッチセンサとシリアル通信をするメモです。使用するPSoCは「CY8C4025AXI-S412」で、タッチセンサのオンオフ情報を、シリアル送信するサンプルです。

何も考えずにタッチセンサとシリアル通信を一緒に使うと、信号が文字化けしてしまいました。理由は、シリアル送信の実行の直後に、タッチセンサの再スキャンをしているためでした。シリアル信号が送信完了するまで時間がかかるのに、それを待たずにタッチセンサ処理が始まり、シリアル信号のタイミングがズレていくんだと思われます。解決するにはシリアル送信のプログラムを書く場所がポイントでした。

“PSoC4 : CapSense & UART(文字化けないポイント)” の続きを読む

塗装時の変形を抑える実験(1)

ちょうど1年前の今頃にも、木彫に液体ガラスを施工するために「接着と塗装の実験」をしていました。

当時は、お湯に4時間漬けるところ、途中で変形したため2時間で引き上げ、その後、水分を含んだ木が柔らかいうちに、なんとかクランプで挟んで、変形を抑えながら乾燥させることができました。しかしこの工程は見直す必要がありました。

“塗装時の変形を抑える実験(1)” の続きを読む

SonicPiで曲作り 5

use_bpm 45
use_random_seed 1

index = -1
s_index = 0
b_index = 0

s = [
  ##| 0,1,2,3,4,5,6
  0,1,2,3,4,5,3,4,1,2,5,6
];

c = []


##| scale(:A, :ritusen)
##| sc_name =  :minor_pentatonic
##| sc_name = :egyptian
##| sc_name =:hex_dorian
sc_name = :ritusen

c[0] = [
  [scale(:Es4 ,sc_name) ,0.125,32],
  [scale(:As4 ,sc_name) ,0.125,32],
  [scale(:Ds4 ,sc_name) ,0.125,32],
  [scale(:Es4 ,sc_name) ,0.125,32],
]
c[1]=[
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
]
c[2]=[
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
  [scale(:Ds3 ,sc_name) ,0.25,16],
]
c[3]=[
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:Ds4 ,sc_name) ,0.25,16],
  [scale(:Es4 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
]
c[4]=[
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
  [scale(:Ds4 ,sc_name) ,0.25,16],
]
c[5]=[
  [scale(:Es4 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
]
c[6]=[
  [scale(:Es4 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
]

a = c[0][0]

with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :loop0 do
    use_octave 1
    cue :loop0
    
    index = index+1
    if(index >= c[s[s_index]].length)
      index = 0
      s_index = s_index + 1
      if(s_index >= s.length)
        s_index = 0
      end
    end
    a =  c[s[s_index]][index]
    
    
    a[2].times do
      print "index ",index, "s ", s[s_index],"t ",(s_index*4+index)
      synth :sine ,
        note: a[0].shuffle.take(2),
        attack: 0, release: 0.1, amp: 0.5, pan: rrand(-0.7, 0.7)
      if((s_index*4+index) >=4)
        cue :bd
        b_index = 0
      end
      sleep a[1]
    end
  end
end

with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :loop2 do
    sync "/live_loop/loop0"
    use_octave 1
    synth :pluck , note: a[0].shuffle.take(2), attack: 0.125, release: 2.15, amp: 0.8
    sleep 1;
  end
end


with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :loop5  do
    use_synth :blade
    play note: a[0].pick(2), attack: 0.5, release: 8, amp: 0.15, vibrato_rate: rand(0.01..2), pan: rrand(-0.7, 0.7)
    play note: a[0].pick(2)-12, attack: 0.25, release: 8, amp: 0.15, vibrato_rate: rand(0.01..2), pan: rrand(-0.7, 0.7)
    sleep 2;
  end
end


with_fx :reverb, room: 0.7, mix: 0.7 do
  live_loop :base do
    sync "/live_loop/loop0"
    sync "/cue/bd"
    4.times do
      use_octave 1
      synth :pluck ,
        note: a[0].pick(b_index % 4),
        attack: 0.2, release: 0.25, amp: 0.5
      b_index = b_index + 1
      sleep a[1]/2
    end
  end
end


live_loop :bd1 do
  sync "/live_loop/loop0"
  sync "/cue/bd"
  sample :bd_ada, amp: 0.8
  sleep 0.5
  sleep 0.25
  sample :bd_ada, amp: 0.4
  sleep 0.25
  sample :bd_ada, amp: 0.4
  sleep 0.25
  sample :bd_ada, amp: 0.4
  sleep 0.25
end
live_loop :bd2 do
  sync "/live_loop/loop0"
  sync "/cue/bd"
  sleep 2
  sample :bd_ada, amp: 0.6
  sleep 0.5
  sleep 0.25
  sample :bd_ada, amp: 0.2
  sleep 0.25
  sample :bd_ada, amp: 0.2
  sleep 0.25
  sample :bd_ada, amp: 0.2
  sleep 0.25
end

SonicPiで曲作り 4

use_bpm 45
use_random_seed 1

index = -1
s_index = 0
b_index = 0

s = [
  0,1,2,3,4,5,6
  ##| 0,1,2,3,4,5,3,4,1,2,5,6
];

c = []

##| sc_name =  :minor_pentatonic
sc_name = :dorian

c[0] = [
  [scale(:Es4 ,sc_name) ,0.125,32],
  [scale(:As4 ,sc_name) ,0.125,32],
  [scale(:Ds4 ,sc_name) ,0.125,32],
  [scale(:Es4 ,sc_name) ,0.125,32],
]
c[1]=[
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
]
c[2]=[
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
  [scale(:Ds3 ,sc_name) ,0.25,16],
]
c[3]=[
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:Ds4 ,sc_name) ,0.25,16],
  [scale(:Es4 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
]
c[4]=[
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
  [scale(:Ds4 ,sc_name) ,0.25,16],
]
c[5]=[
  [scale(:Es4 ,sc_name) ,0.25,16],
  [scale(:Es3 ,sc_name) ,0.25,16],
  [scale(:Ds3 ,sc_name) ,0.25,16],
  [scale(:As3 ,sc_name) ,0.25,16],
]
c[6]=[
  [scale(:Es4 ,sc_name) ,0.125,32],
  [scale(:Es3 ,sc_name) ,0.125,32],
  [scale(:Ds3 ,sc_name) ,0.125,32],
  [scale(:As3 ,sc_name) ,0.125,32],
]

a = c[0][0]

with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :loop0 do
    use_octave 1
    cue :loop0
    
    index = index+1
    if(index >= c[s[s_index]].length)
      index = 0
      s_index = s_index + 1
      if(s_index >= s.length)
        s_index = 0
      end
    end
    a =  c[s[s_index]][index]
    
    
    a[2].times do
      print "index ",index, "s ", s[s_index],"t ",(s_index*4+index)
      synth :sine ,
        note: a[0].shuffle.take(2),
        attack: 0, release: 0.1, amp: 0.5, pan: rrand(-0.7, 0.7)
      if((s_index*4+index) >=4)
        cue :bd
        b_index = 0
      end
      sleep a[1]
    end
  end
end

with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :loop2 do
    sync "/live_loop/loop0"
    use_octave 1
    synth :piano , note: a[0].shuffle.take(2), attack: 0.125, release: 2.15, amp: 0.8
    sleep 1;
  end
end


with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :loop5  do
    use_synth :saw;
    play note: a[0].pick(2), attack: 0.5, release: 8, amp: 0.1, vibrato_rate: rand(0.01..2)
    play note: a[0].pick(2)-12, attack: 0.25, release: 8, amp: 0.1, vibrato_rate: rand(0.01..2)
    sleep 2;
  end
end


with_fx :reverb, room: 0.7, mix: 0.7 do
  live_loop :base do
    sync "/live_loop/loop0"
    sync "/cue/bd"
    4.times do
      use_octave 1
      synth :piano ,
        note: a[0].pick(b_index % 4),
        attack: 0.2, release: 0.25, amp: 0.5
      b_index = b_index + 1
      sleep a[1]/2
    end
  end
end


live_loop :bd1 do
  sync "/live_loop/loop0"
  sync "/cue/bd"
  sample :bd_ada, amp: 0.8
  sleep 0.5
  sleep 0.25
  sample :bd_ada, amp: 0.4
  sleep 0.25
  sample :bd_ada, amp: 0.4
  sleep 0.25
  sample :bd_ada, amp: 0.4
  sleep 0.25
end
live_loop :bd2 do
  sync "/live_loop/loop0"
  sync "/cue/bd"
  sleep 2
  sample :bd_ada, amp: 0.6
  sleep 0.5
  sleep 0.25
  sample :bd_ada, amp: 0.2
  sleep 0.25
  sample :bd_ada, amp: 0.2
  sleep 0.25
  sample :bd_ada, amp: 0.2
  sleep 0.25
end

SonicPiで曲作り 3

use_bpm 45
use_random_seed 1

tr = 0
t = 0
c = [
  :Gb3,:Gb3,:Gb3,:Gb3,:Cb3,:Db3,:Cb3,:Db3,
  :Ab3,:Ab3,:Ab3,:Ab3,:Bb3,:Bb3,:Bb3,:Bb3,
  :Eb4,:Eb4,:Db4,:Db4,:Gb4,:Gb4
]
a = c[0]


in_thread do
  cue :start
  with_fx :reverb, room: 0.99, mix: 0.7 do
    synth :saw , note: scale(:Gb3, :minor_pentatonic).shuffle.take(3), attack: 1.5, release: 16, amp: 0.1
    sleep 2;
    synth :saw , note: scale(:Gb4, :minor_pentatonic).shuffle.take(3), attack: 1.0, release: 12, amp: 0.1
    sleep 2;
    synth :saw , note: scale(:Gb5, :minor_pentatonic).shuffle.take(3), attack: 0.5, release: 8, amp: 0.1
    sleep 4;
  end
end

with_fx :reverb, room: 0.99, mix: 0.7 do
  4.times do
    synth :sine , note: scale(:Gb3, :minor_pentatonic).shuffle.take(2), attack: 0, release: 0.1, amp: 0.2
    sleep 1;
    synth :sine , note: scale(:Gb4, :minor_pentatonic).shuffle.take(2), attack: 0, release: 0.1, amp: 0.2
    sleep 1
  end
end

cue :bd1
cue :bd

live_loop :zoo do
  cue :bd1
  tr = c[t]
  if(tr != nil)
    a = tr
  else
    t=0
    tr = c[t]
    a = tr
  end
  
  t=t+1
  print t,a
  sleep 2
end

live_loop :bd1 do
  sync "/cue/bd"
  sample :bd_ada, amp: 0.8
  sleep 0.5
  sleep 0.25
  sample :bd_ada, amp: 0.4
  sleep 0.25
end

live_loop :bd2 do
  sync "/cue/bd"
  sleep 3
  sample :bd_ada, amp: 0.4
  sleep 0.5
  sleep 0.25
  sample :bd_ada, amp: 0.2
end


with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :loop2 do
    ##| sync "/cue/bd1"
    cue :bd
    synth :piano ,
      note: scale(a, :minor_pentatonic, num_octaves: 2).shuffle.take(3),
      attack: 0, release: 0.15, amp: [1, 0.5, 0.25].choose
    sleep 4;
  end
end


with_fx :reverb, room: 0.99, mix: 0.7 do
  live_loop :melo do
    
    4.times do
      synth :piano ,
        note: scale(a, :minor_pentatonic, num_octaves: 2).shuffle.take(3),
        attack: 0, release: 2, amp: 0.5
      sleep 1
      
      use_synth :piano;
      32.times do
        play choose(scale(a, :minor_pentatonic, num_octaves: 2)), attack: 0, release: 0.5, amp: [0.2, 0.1, 0.4].choose
        sleep 0.125
      end
    end
    
  end
end


with_fx :reverb, room: 0.5, mix: 0.7 do
  live_loop :melo2 do
    
    if(!one_in(8))
      32.times do
        synth :pretty_bell ,
          note: scale(a, :minor_pentatonic, num_octaves: 2).shuffle.take(3),
          attack: 0, release: 0.15, amp: [0.2, 0.1, 0.25].choose
        sleep 0.125
      end
    else
      
      28.times do
        synth :pretty_bell ,
          note: scale(a, :minor_pentatonic, num_octaves: 2).shuffle.take(3),
          attack: 0, release: 0.15, amp: [0.2, 0.1, 0.25].choose
        sleep 0.125
      end
      
      8.times do
        synth :pretty_bell ,
          note: scale(a, :minor_pentatonic, num_octaves: 2).shuffle.take(3),
          attack: 0, release: 0.15, amp: [0.2, 0.1, 0.25].choose
        sleep 0.125/2
      end
    end
    
  end
end