Exemplo n.º 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)
}
Exemplo n.º 2
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)
	}
}
Exemplo n.º 4
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)
	}
}
Exemplo n.º 5
0
func NewRPi() *RPi {
	pi := &RPi{LEDs: []string{"GPIO_17", "GPIO_27", "GPIO_22"}}
	err := embd.InitGPIO()
	if err != nil {
		fmt.Println(err.Error())
	}
	for _, l := range pi.LEDs {
		err := embd.SetDirection(l, embd.Out)
		if err != nil {
			fmt.Println(err.Error())
		}
	}
	return pi
}