File: example_pin.py

package info (click to toggle)
simulavr 1.0.0%2Bgit20160221.e53413b-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,740 kB
  • sloc: cpp: 35,491; python: 6,995; ansic: 3,567; makefile: 1,075; sh: 653; asm: 414; tcl: 320; javascript: 32
file content (81 lines) | stat: -rw-r--r-- 2,341 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Python Script
from __future__ import print_function
import pysimulavr

class XPin(pysimulavr.Pin):
  
  def SetInState(self, pin):
    pysimulavr.Pin.SetInState(self, pin)
    print("<pin: id=%s, in=%s/%0.2fV, out=%s, aPin=%0.2fV>" % (id(self),
                                                               pin.toChar(),
                                                               pin.GetAnalogValue(vcc),
                                                               self.toChar(),
                                                               self.GetAnalogValue(vcc)), end=' ')
    
def printPin(pid, pin, withID = False):
  if withID:
    print("  pin %d: id=%s, (char)pin='%s', pin.GetAnalogValue(vcc)=%0.2fV" % (pid,
                                                                               id(pin),
                                                                               pin.toChar(),
                                                                               pin.GetAnalogValue(vcc)))
  else:
    print("  pin %d: (char)pin='%s', pin.GetAnalogValue(vcc)=%0.2fV" % (pid,
                                                                        pin.toChar(),
                                                                        pin.GetAnalogValue(vcc)))

if __name__ == "__main__":

  vcc = 5.0
  print("set vcc=%0.2fV ..." % vcc)
  print("create 2 pins ...")
  p1 = XPin()
  p1.outState = pysimulavr.Pin.LOW
  printPin(1, p1, True)
  
  p2 = XPin()
  p2.outState = pysimulavr.Pin.TRISTATE
  printPin(2, p2, True)
  
  print("\ncreate net ...")
  n = pysimulavr.Net()
  print("  add pin 1:", end=' ')
  n.Add(p1)
  print("")
  print("  add pin 2:", end=' ')
  n.Add(p2)
  print("")
  
  printPin(1, p1)
  printPin(2, p2)

  print("\nset pin 2 output to PULLUP:", end=' ')
  p2.SetPin("h")
  print("")
  printPin(1, p1)
  printPin(2, p2)

  print("\nset pin 1 output to HIGH:", end=' ')
  p1.SetPin("H")
  print("")
  printPin(1, p1)
  printPin(2, p2)

  print("\nset pin 2 output to TRISTATE:", end=' ')
  p2.SetPin("t")
  print("")
  printPin(1, p1)
  printPin(2, p2)

  print("\nset pin 1 output to TRISTATE:", end=' ')
  p1.SetPin("t")
  print("")
  printPin(1, p1)
  printPin(2, p2)

  print("\nset pin 2 output to LOW:", end=' ')
  p2.SetPin("L")
  print("")
  printPin(1, p1)
  printPin(2, p2)
  
# EOF