我已經在Arduino中編寫了循環通過3個LED顏色燈的代碼,但它似乎(代碼)容易出錯,所以我試圖想出一個新的寫法。由於複雜性,我將堅持我想要做的phesdo代碼。那就是:在Arduino中創建一個更好的循環
If (red LED isn't max and green LED is 0 and blue LED is 0)
{inc red LED; update dot matrix}
If (red LED is max and green LED isn't max and blue LED is 0)
{inc green LED; update dot matrix}
If ((red LED is/has-been max but not 0) and green LED is max and blue LED is 0)
{dec red; update dot matrix}
If (red LED is 0 and green LED is max and blue LED isn't max)
{inc blue; update dot matrix}
If (red LED is 0 and (green LED is/has-been max but not 0) and blue LED is max)
{dec green; update dot matrix}
If (red LED isn't Max and green LED is 0 and blue is Max)
{inc red; update dot matrix}
If (red LED is Max and green LED is 0 and (blue LED is/has-been Max but not 0))
{dec blue; update dot matrix}
Update LED Driver;
注:對於視覺它是一個色輪去紅 - >橙色>綠 - > teal->藍 - >粉紅 - >重複
需要說明的是,這一切是在退出取回其他數據之前僅運行一次的循環中。然後它必須返回到這個循環並且記住它所遺留的顏色位置。除此之外,將所有這些內容封裝在循環中併線性執行它將非常簡單。因爲它必須增加或減少一種顏色,所以如果你願意,可以理解它的顏色位置,更新LED驅動程序,然後回到增加或減少記錄停止的位置。因此,任何人都有更好的代碼方法,僞風格,除了這個複雜的if語句風格之外,我可以使用它。
「所有這些都在一個只運行一次的循環中」那麼它在循環中有什麼意義呢? – ApproachingDarknessFish 2013-04-26 17:57:04
沒有抱歉,這個循環,但我不得不在更新顏色坐在它之前和之後的事情。我需要改變顏色一點點更新LED驅動器,然後做其他事情,然後再回來,並更新一點,重複一遍。 – Nimjox 2013-04-26 18:01:15
請勿使用循環,請使用計時器。 – 2013-04-26 18:29:29