#! /bin/bash
period=10000
position=0

/data/rgb.sh 0 0 0 $period
rpath=/sys/class/pwm/pwmchip0
gpath=/sys/class/pwm/pwmchip1
bpath=/sys/class/pwm/pwmchip2

while :
do
    if [ $position -lt 34 ]; then
        red=$((position * 3))
        green=$((100 - (position * 3)))
        blue=0
    elif [ $position -lt 67 ]; then
        red=$((100 - ((position - 33) * 3)))
        green=0
        blue=$(((position - 33) * 3))
    else
        red=0
        green=$(((position - 66) * 3))
        blue=$((100 - ((position - 66) * 3)))
    fi

    echo "$((red * period / 100))" > $rpath/pwm0/duty_cycle
    echo "$((green * period / 100))" > $gpath/pwm0/duty_cycle
    echo "$((blue * period / 100))" > $bpath/pwm0/duty_cycle

    position=$(((position + 1) % 100))
    sleep 0.05
done
