File size: 1,027 Bytes
420ca3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""naderEren.195

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1DpxhB_ApIH6oxffzDMDc5GYgn_PqdFRB
"""

import RPi.GPIO as GPIO
from time import sleep
dt=.1
b1=40
b2=38
b1State=1
b1StateOld=1
b2State=1
b2StateOld=1
LEDPin=37
DC=99
GPIO.setmode(GPIO.BOARD)
GPIO.setup(b1,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(b2,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(LEDPin,GPIO.OUT)
myPWM=DPIO.GWM(LEDPin,100)
myPWM.start(DC)
BP=10

try:
  while True:
    b1State=GPIO.input(b1)
    b2State=GPIO.input(b2)
    if b1StateOld==0 and b1State==1:
      BP=BP-1
      DC=(1.5849)^BP
      print('Dim Event')
    if b2StateOld==0 and b2State==1:
      BP=BP+1
      DC=(1.5849)^BP
      print('Bright Event')
    if DC>99:
      DC=99
    if DC<0
      DC=0
    print(DC)
    myPWM.ChangeDutyCycle(DC)
    b1StateOld=b1State
    b2StateOld=b2State
    sleep(dt)

except keyboardInterrupt:
  myPWM.stop()
  GPIO.clenup()
  print('GPIO Ready to Perform')