Skip to content

Instantly share code, notes, and snippets.

@trianglegrrl
Created July 22, 2015 01:14
Show Gist options
  • Save trianglegrrl/89143f51b0222c50c1fc to your computer and use it in GitHub Desktop.
Save trianglegrrl/89143f51b0222c50c1fc to your computer and use it in GitHub Desktop.
SU GSP NCS PB WTF
import RPi.GPIO
import os
import time
from pyslack import SlackClient
import requests
import json
import string
url = "https://hooks.slack.com/services/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"
RPi.GPIO.setmode(RPi.GPIO.BCM)
RPi.GPIO.setup(3, RPi.GPIO.OUT)
RPi.GPIO.setup(2, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP)
previous_button_state = RPi.GPIO.LOW
headers = {'content-type': 'application/json'}
while True:
button_pressed = RPi.GPIO.input(2) == RPi.GPIO.LOW
if button_pressed == True:
RPi.GPIO.output(3, True)
else:
RPi.GPIO.output(3, False)
if button_pressed != previous_button_state:
if button_pressed:
message = "Button pressed"
else:
message = "Button released"
payload = { "text": message }
response = requests.post(url, data=json.dumps(payload), headers=headers)
previous_button_state = button_pressed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment