Пример #1
0
func (p *PCD8544) init() {
	if err := embd.InitGPIO(); err != nil {
		panic(err)
	}
	// All pin direction are output
	embd.SetDirection(p.PIN_SCLK, embd.Out)
	embd.SetDirection(p.PIN_DIN, embd.Out)
	embd.SetDirection(p.PIN_DC, embd.Out)
	embd.SetDirection(p.PIN_CS, embd.Out)
	embd.SetDirection(p.PIN_RST, embd.Out)

	// Reset controller state
	embd.DigitalWrite(p.PIN_RST, embd.High)
	embd.DigitalWrite(p.PIN_CS, embd.High)
	embd.DigitalWrite(p.PIN_RST, embd.Low)
	// delay(100)
	time.Sleep(100 * time.Millisecond)
	embd.DigitalWrite(p.PIN_RST, embd.High)

	// LCD parameters
	p.send(LCD_CMD, 0x21) // extended instruction set control (H=1)
	p.send(LCD_CMD, 0x13) // bias system (1:48)
	p.send(LCD_CMD, 0xc2) // default Vop (3.06 + 66 * 0.06 = 7v)

	p.Clear()

	// Activate LCD
	p.send(LCD_CMD, 0x08) // display blank
	p.send(LCD_CMD, 0x0c) // normal mode (0x0d = inverse mode)
	// delay(100)
	time.Sleep(100 * time.Millisecond)

	// Place the cursor at the origin
	p.SetCursor(0, 0)
}
Пример #2
0
func (r *RPi) LedsCycle(repeat int) {
	r.LedsOff()
	for i := 0; i < repeat; i++ {
		for _, l := range r.LEDs {
			embd.DigitalWrite(l, embd.High)
			time.Sleep(50 * time.Millisecond)
			embd.DigitalWrite(l, embd.Low)
		}
	}
}
Пример #3
0
func shiftOut(dataPin uint8, clockPin uint8, bitOrder uint8, val uint8) {
	var (
		one   uint8 = 1
		seven uint8 = 7
	)

	for i := uint8(0); i < 8; i++ {
		if bitOrder == LSBFIRST {
			embd.DigitalWrite(dataPin, pre_shift(val&(one<<i)))
		} else {
			embd.DigitalWrite(dataPin, pre_shift(val&(one<<(seven-i))))
		}
		embd.DigitalWrite(clockPin, embd.High)
		embd.DigitalWrite(clockPin, embd.Low)
	}
}
Пример #4
0
func main() {
	embd.InitGPIO()
	defer embd.CloseGPIO()

	embd.SetDirection(10, embd.Out)
	embd.DigitalWrite(10, embd.High)
}
func (l *LightsController) Toggle_led_light(rw http.ResponseWriter, req *http.Request) {
	flag.Parse()
	embd.InitGPIO()

	body, err := ioutil.ReadAll(req.Body)

	var lig models.Light

	if err != nil {
		panic(err)
	}
	err = json.Unmarshal(body, &lig)
	if err != nil {
		panic(err)
	}
	fmt.Println(lig.Pin_number)

	if lig.Status == true {
		embd.SetDirection(lig.Pin_number, embd.Out)
		embd.DigitalWrite(lig.Pin_number, embd.High)
		b, err := json.Marshal(models.LightMessage{
			Success: "True",
			Message: "Switched On!!!",
		})
		if err != nil {
			log.Fatal(err)
		}
		rw.Header().Set("Content-Type", "application/json")
		rw.Write(b)
	} else {
		embd.SetDirection(lig.Pin_number, embd.Out)
		embd.DigitalWrite(lig.Pin_number, embd.Low)
		b, err := json.Marshal(models.LightMessage{
			Success: "false",
			Message: "Switched Off!!!",
		})
		if err != nil {
			log.Fatal(err)
		}
		rw.Header().Set("Content-Type", "application/json")
		rw.Write(b)
	}
}
Пример #6
0
func main() {
	if err := embd.InitGPIO(); err != nil {
		panic(err)
	}
	defer embd.CloseGPIO()

	if err := embd.SetDirection(10, embd.Out); err != nil {
		panic(err)
	}
	if err := embd.DigitalWrite(10, embd.High); err != nil {
		panic(err)
	}

	time.Sleep(1 * time.Second)

	if err := embd.SetDirection(10, embd.In); err != nil {
		panic(err)
	}
}
Пример #7
0
func (r *RPi) LedsOff() {
	for _, l := range r.LEDs {
		embd.DigitalWrite(l, embd.Low)
	}
}
Пример #8
0
func (r *RPi) LedsOn() {
	for _, l := range r.LEDs {
		embd.DigitalWrite(l, embd.High)
	}
}
Пример #9
0
func (p *PCD8544) send(type_ uint8, data uint8) {
	embd.DigitalWrite(p.PIN_DC, int(type_))
	embd.DigitalWrite(p.PIN_CS, embd.Low)
	shiftOut(p.PIN_DIN, p.PIN_SCLK, MSBFIRST, data)
	embd.DigitalWrite(p.PIN_CS, embd.High)
}