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?

More than 3 years have passed since last update.

【初心者向け】ラズパイ4でLチカ&Slack通知 Python

Last updated at Posted at 2020-05-17

1.Lチカ

IMG_20200517_120448.jpg

import RPi.GPIO as GPIO
import time
import numpy as np


def Lchika():
    PNO = 17#gpio readallでピン番号をチェック

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(PNO, GPIO.OUT)

    c = 0

    for i in range(np.random.randint(4,10)):
        GPIO.output(PNO, GPIO.HIGH)
        time.sleep(0.4)
        GPIO.output(PNO, GPIO.LOW)
        time.sleep(0.4)
        c += 1 

    GPIO.cleanup()

    return c

光った回数をslackで通知します.

Incoming Webhook を使うと簡単にSlack通知できます.

def slack_post(c):

    WEB_HOOK_URL = "https://hooks.slack.com/services/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"
    requests.post(WEB_HOOK_URL, data = json.dumps({
        'text': f'LEDが{c}回光りました.',  #通知内容
        'link_names': 1,  #名前をリンク化
    }))

参考にさせていただきました
PythonでSlackのIncoming Webhookを試してみる
[RaspberryPi3でPythonを使ってLチカさせる]
(https://qiita.com/westvirginia/items/4e75b5220f6bfddf21d1)

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?