0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AD値を7セグに表示

0
Last updated at Posted at 2026-11-19

PICで拾ったAD値を7セグに表示してみました。

LEDADDR = 0x20
PICADDR = 0x04

def getvol(t)
  t.write(PICADDR, 0, 0)
  vol = t.read(PICADDR, 1, 0) << 8 |  t.read(PICADDR, 1, 1)
  t.read(PICADDR, 1, 2)
  vol
end

def mkbit n
  r = 0
  while n != 0 do
    a = n % 10
    r |= 1 << a
    n /= 10
  end
  r
end

def dispvol(t, i)
num = [
134567, # 0
13, # 1
12567, # 2
12367, # 3
1234, # 4
23467, # 5
234567, # 6
137, # 7
1234567, # 8
123467 # 9
]

  c4 = mkbit(num[i % 10])
  c3 = mkbit(num[(i / 10) % 10])
  c2 = mkbit(num[(i / 100) % 10])
  c1 = mkbit(num[i / 1000])
  t.write(LEDADDR, [0x00, c1 + 1, c2, c3, c4])
end

t = BsdIic.new(0)

lastvol = getvol(t)
dispvol(t, lastvol)

loop do
  vol = getvol(t)
  if vol != lastvol
    dispvol(t, vol)
    lastvol = vol
  end
  usleep 100_000
end

写真(2026-11-19 9.10).jpg

このI2Cのドーターボードは3.3Vと5Vに対応していて、DCDCコンバーターで3.3Vから5Vを作ってI2Cの信号はPCA9306でレベル変換してます。PIC側は3.3Vで動いていて、7セグは5Vで動いています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?