Met deze code kan je een RGB led bedienen met 6 knoppen.
'**************************************************************** '* Naam : RGB-led controller * '* Auteur : Coenen Stijn [Stynus] * '* Notice : Copyright (c) 2008 ? SchemaTheek.net * '* : All Rights Reserved * '* Date : 02/05/2008 * '* Version : 1.0 * '**************************************************************** Device 16F877A Config WDT_Off, PWRTE_ON, HS_OSC , LVP_off XTAL 20 ALL_DIGITAL = true '**************************************************************** Symbol Led_Rood = PORTD.1 : TRISD.1 = 0 Symbol R_plus = PORTA.0 : TRISA.0 = 1 Dim R_plus_bit As Bit Symbol R_min = PORTA.1 : TRISA.1 = 1 Dim R_min_bit As Bit Dim rood As Byte Symbol Led_Groen = PORTD.0 : TRISD.0 = 0 Symbol G_plus = PORTA.2 : TRISA.2 = 1 Dim G_plus_bit As Bit Symbol G_min = PORTA.3 : TRISA.3 = 1 Dim G_min_bit As Bit Dim groen As Byte Symbol Led_Blauw = PORTC.3 : TRISC.3 = 0 Symbol B_plus = PORTA.4 : TRISA.4 = 1 Dim B_plus_bit As Bit Symbol B_min = PORTA.5 : TRISA.5 = 1 Dim B_min_bit As Bit Dim blauw As Byte Dim index As Byte 'Lcd Declare LCD_DTPIN PORTD.4 Declare LCD_ENPIN PORTD.2 Declare LCD_RSPIN PORTD.3 Declare LCD_INTERFACE 4 Declare LCD_LINES 2 '**************************************************************** Cls Print At 1,1, "R G B " While 1 = 1 If rood > 0 Then High Led_Rood EndIf If groen > 0 Then High Led_Groen EndIf If blauw> 0 Then High Led_Blauw EndIf For index = 0 To 32 If index = rood Then Low Led_Rood EndIf If index = groen Then Low Led_Groen EndIf If index = blauw Then Low Led_Blauw EndIf DelayUS 50 Next Print At 2,1, DEC2 rood, " ", DEC2 groen, " ", DEC2 blauw '*************** 'Rood If R_plus = 0 Then If R_plus_bit = 0 Then If rood < 32 Then Inc rood EndIf R_plus_bit = 1 EndIf Else R_plus_bit = 0 EndIf If R_min = 0 Then If R_min_bit = 0 Then If rood > 0 Then Dec rood EndIf R_min_bit = 1 EndIf Else R_min_bit = 0 EndIf '*************** 'Groen If G_plus = 0 Then If G_plus_bit = 0 Then If groen < 32 Then Inc groen EndIf G_plus_bit = 1 EndIf Else G_plus_bit = 0 EndIf If G_min = 0 Then If G_min_bit = 0 Then If groen > 0 Then Dec groen EndIf G_min_bit = 1 EndIf Else G_min_bit = 0 EndIf '*************** 'Blauw If B_plus = 0 Then If B_plus_bit = 0 Then If blauw < 32 Then Inc blauw EndIf B_plus_bit = 1 EndIf Else B_plus_bit = 0 EndIf If B_min = 0 Then If B_min_bit = 0 Then If blauw > 0 Then Dec blauw EndIf B_min_bit = 1 EndIf Else B_min_bit = 0 EndIf Wend '**************************************************************** End