OpenIPC / firmware

Alternative IP Camera firmware from an open community
https://openipc.org
MIT License
1.25k stars 239 forks source link

Ingenic T21 - Define GPIO pin numbers #1214

Closed kangz543g closed 9 months ago

kangz543g commented 9 months ago

!/bin/bash

Ingenic T21 - Define GPIO pin numbers

GREEN_LED_GPIO=75 RED_LED_GPIO=78

Export GPIO pins

echo "$GREEN_LED_GPIO" > /sys/class/gpio/export echo "$RED_LED_GPIO" > /sys/class/gpio/export

Set the direction to "out"

echo "out" > "/sys/class/gpio/gpio$GREEN_LED_GPIO/direction" echo "out" > "/sys/class/gpio/gpio$RED_LED_GPIO/direction"

Function to control LED state

function control_led { local gpio_pin=$1 local state=$2

echo "$state" > "/sys/class/gpio/gpio$gpio_pin/value"

}

Function to toggle LED state

function toggle_led { local gpio_pin=$1

current_state=$(cat "/sys/class/gpio/gpio$gpio_pin/value")
if [ "$current_state" -eq 0 ]; then
    control_led "$gpio_pin" 1
else
    control_led "$gpio_pin" 0
fi

}

Main loop to blink LEDs

while true; do

Turn on the green LED

control_led "$GREEN_LED_GPIO" 1
sleep 1

# Turn off the green LED
control_led "$GREEN_LED_GPIO" 0
sleep 1

# Toggle the red LED
toggle_led "$RED_LED_GPIO"
sleep 1

done

chmod +x leds.sh

run ./leds.sh -sh: ./leds.sh: not found

what???

viktorxda commented 9 months ago

Merged with #1209