Skip to content

Instantly share code, notes, and snippets.

@MartinRGB
Last active November 17, 2023 07:52
Show Gist options
  • Save MartinRGB/fc13d2a550aabf76ab8ed585ec16ac36 to your computer and use it in GitHub Desktop.
Save MartinRGB/fc13d2a550aabf76ab8ed585ec16ac36 to your computer and use it in GitHub Desktop.

Revisions

  1. MartinRGB revised this gist Nov 17, 2023. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion Light_Temp_Control_Lamp.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    ![image](https://user-images.githubusercontent.com/7036706/283719014-0f603f3d-f833-41f0-be34-d5c6a06a21f0.png)

    <img src="https://user-images.githubusercontent.com/7036706/283719014-0f603f3d-f833-41f0-be34-d5c6a06a21f0.png" width="50%" height="50%"/>
    <img src="https://user-images.githubusercontent.com/7036706/283719916-db754e49-fdb8-4f64-ad55-185a38fab2dd.jpg" width="50%" height="50%"/>

    ```c

  2. MartinRGB created this gist Nov 17, 2023.
    43 changes: 43 additions & 0 deletions Light_Temp_Control_Lamp.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    ![image](https://user-images.githubusercontent.com/7036706/283719014-0f603f3d-f833-41f0-be34-d5c6a06a21f0.png)

    ```c

    #define ROTATOR_PIN A0
    #define BUTTON_PIN 10

    #define WL_PIN 3
    #define CL_PIN 5

    float rotatorValue; //variable to store sensor value
    byte buttonState;
    float mapBrightnessValue;
    float mapWarmValue = 1;
    float mapColdValue = 1;
    void setup() {
    Serial.begin(9600);
    pinMode(ROTATOR_PIN, INPUT);
    pinMode(BUTTON_PIN, INPUT);
    pinMode(WL_PIN,OUTPUT);
    pinMode(CL_PIN,OUTPUT);
    }

    void loop() {
    buttonState = digitalRead(BUTTON_PIN);
    rotatorValue = analogRead(ROTATOR_PIN);
    Serial.println(rotatorValue);

    if (buttonState == HIGH) {
    Serial.println("Button is pressed");
    mapBrightnessValue = map(rotatorValue,0,1023,0,42);
    analogWrite(WL_PIN, mapBrightnessValue * 1.5);
    analogWrite(CL_PIN, (42 - mapBrightnessValue)* 1.5);
    }
    else {
    Serial.println("Button is not pressed");
    mapBrightnessValue = map(rotatorValue,0,1023,0,42);
    analogWrite(WL_PIN, mapBrightnessValue);
    analogWrite(CL_PIN, mapBrightnessValue);
    }

    }
    ```