#!/usr/bin/env python

# PyClock - Raspberry Pi Econet Clock
# ISW 5/iv/2021
# Switch on Clock
# Uses pigpio library - install and start with sudo pigpiod
#
# Two GPIO pins for clock

import pigpio

GPIO1=18  # GPIO18 = pin 12
GPIO2=12  # GPIO12 = pin 32 ; any spare pins can be used

# Set clock speed; Clock rate = (mark/(mark+space))*1000 KHz

mark=1
space=4

square = []

#                          ON       OFF    MICROS
square.append(pigpio.pulse(1<<GPIO1, 1<<GPIO2, mark))
square.append(pigpio.pulse(1<<GPIO2, 1<<GPIO1, space))

pi = pigpio.pi() # connect to local Pi

pi.set_mode(GPIO1, pigpio.OUTPUT)
pi.set_mode(GPIO2, pigpio.OUTPUT)

pi.wave_clear()

pi.wave_add_generic(square)
pyclock = pi.wave_create()

pi.wave_send_repeat(pyclock)
