본문 바로가기

3D Printer/OctoPrint

Chamber Manager Board 제작 #12 (LED Control Class 추가)

【 3D 프린터 챔버 만들기 】



[ Control Board 제작 #12 : LED Control Class 추가 ]



□ 추가 사항


 - Light Control 구현



[ ChamberManager.ino Execute 함수 수정 ]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
bool Execute(CMD cmd) {
    char temp[10];
 
    switch(cmd.Object) {
      case   0// Hellow
        Serial.println(F("OK O0 R0"));
        return true;
      case  10// Write settings to eeprom
        if(cmd.Status == WRITE) {
          Serial.printf(F("OK O%d"), cmd.Object);
          // Todo : Write setting to eeprom
          return true;
        }
        return false;
      case  20// Setting load & save
        if(cmd.Status == WRITE) {
 
        } if(cmd.Status == READ) {
 
        }
        return false;        
      case 111// Ventil Servo Max position
        if(cmd.Status == WRITE) {
          g_DoorVentil.setMaxPos(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_DoorVentil.getMaxPos());
        return true;
      case 112// Ventil Servo Min position
        if(cmd.Status == WRITE) {
          g_DoorVentil.setMinPos(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_DoorVentil.getMinPos());
        return true;
      case 113// Filter Servo Max position
        if(cmd.Status == WRITE) {
          g_DoorFilter.setMaxPos(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_DoorFilter.getMaxPos());
        return true;
      case 114// Filter Servo Mix position
        if(cmd.Status == WRITE) {
          g_DoorFilter.setMinPos(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_DoorFilter.getMinPos());
        return true;
      case 200// Temp Control mode
        if(cmd.Status == WRITE) {
          switch(cmd.Value) {
            case 1// ON/OFF
              g_TempControl.setCtrlMode(ONOFF);
              break;
            case 2// PID
              g_TempControl.setCtrlMode(PID);
              break;
            default// MANUAL
              g_TempControl.setCtrlMode(MANUAL);
              break;
          }
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_TempControl.getCtrlMode());
        return true;
      case 201// Temperature target
        if(cmd.Status == WRITE) {
          g_TempControl.setAmbientTarget(cmd.Value);
        }
        Serial.printf(F("OK O%d %s"), cmd.Object, dtostrf(g_TempControl.getAmbientTarget(), 11, temp));
        return true;
      case 202// Ambient temperature
        if(cmd.Status == READ) {
          Serial.printf(F("OK O%d %s"), cmd.Object, dtostrf(g_fAmbentTemp, 11, temp));
          return true;
        }
        break;
      case 300// FanEnable
        if(cmd.Status == WRITE) {
          if(cmd.Value == 1) {
            g_FanVentil.FanOn();
            g_FanFilter.FanOn();
          }
          else {
            g_FanVentil.FanOff();
            g_FanFilter.FanOff();
          }
          Serial.printf(F("OK O%d"), cmd.Object);
          return true;
        }
        break;
      case 311// Doors angle
        if(cmd.Status == WRITE) {
          g_DoorVentil.setAngle(cmd.Value);
          g_DoorFilter.setAngle(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_DoorVentil.getAngle());
        return true;
      case 312// Fans speed
        if(cmd.Status == WRITE) {
          g_FanVentil.setSpeed(cmd.Value);
          g_FanFilter.setSpeed(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_FanVentil.getSpeed());
        return true;
      case 321// Ventil door angle
        if(cmd.Status == WRITE) {
          g_DoorVentil.setAngle(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_DoorVentil.getAngle());
        return true;
      case 322// Ventil fan speed
        if(cmd.Status == WRITE) {
          g_FanVentil.setSpeed(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_FanVentil.getSpeed());
        return true;
      case 331// Filter door angle
        if(cmd.Status == WRITE) {
          g_DoorFilter.setAngle(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_DoorFilter.getAngle());
        return true;
      case 332// Filter fan speed
        if(cmd.Status == WRITE) {
          g_FanFilter.setSpeed(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_FanFilter.getSpeed());
        return true;
      case 400// Light control mode
        if(cmd.Status == WRITE) {
          g_LightControl.setControlMode(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_LightControl.getControlMode());
        return true;
      case 401// Light on/off
        if(cmd.Status == WRITE) {
          g_LightControl.setCurrentStatus(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_LightControl.getCurrentStatus());
        return true;
      case 411// Light sensitivity
        if(cmd.Status == WRITE) {
          g_LightControl.setSensitivity(cmd.Value);
        }
        Serial.printf(F("OK O%d %d"), cmd.Object, g_LightControl.getSensitivity());
        return true;
      case 421// Read light sensor value
        if(cmd.Status == READ) {
          Serial.printf(F("OK O%d %d"), cmd.Object, g_LightControl.getCurrentSensing());
          return true;
        }
        return false;
      defaultbreak;
    }
 
    return false;
}
cs



[ LightControl.h ]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef LIGHTCONTROL_H
#define LIGHTCONTROL_H
 
#if defined(ARDUINO) && (ARDUINO >= 100)
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif
 
#include <inttypes.h>
 
class LightControl
{
  private:
    int m_nSensitivity = 500;
    int m_ctrlMode = 1;
    int m_statusCurrent = 0;
    int m_nSensorPin;
    int m_nControlPin;
 
  public:
    LightControl();
    LightControl(int nSensor, int nControl);
 
    void CheckLight();
 
    void TurnOn();
    void TurnOff();
 
    int getCurrentSensing();
 
    void setSensorPin(int pin) { m_nSensorPin = pin; };
    int getSensorPin() { return m_nSensorPin; };
    void setControlPin(int pin) { m_nControlPin = pin; };
    int getControlPin() { return m_nControlPin; };
 
    void setSensitivity(int value) { m_nSensitivity = value; };
    int getSensitivity() { return m_nSensitivity; };
    void setControlMode(int mode) { m_ctrlMode = mode; };
    int getControlMode() { return m_ctrlMode; };
    void setCurrentStatus(int status);
    int getCurrentStatus() { return m_statusCurrent; };
};
 
#endif
cs



[ LightControl.cpp ]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "LightControl.h"
 
LightControl::LightControl() {
 
}
 
LightControl::LightControl(int nSensor, int nControl) {
  m_nSensorPin = nSensor;
  m_nControlPin = nControl;
 
  pinMode(m_nControlPin, OUTPUT);
}
 
void LightControl::CheckLight() {
  if(m_ctrlMode == 1) {
    int s = analogRead(m_nSensorPin);
    if(s>m_nSensitivity) {
      TurnOn();
    } else {
      TurnOff();
    }
  }
}
 
void LightControl::TurnOn() {
  setCurrentStatus(1);
}
 
void LightControl::TurnOff() {
  setCurrentStatus(0);
}
 
void LightControl::setCurrentStatus(int status) {
  m_statusCurrent = status;
 
  digitalWrite(m_nControlPin, status);
}
 
int LightControl::getCurrentSensing() {
  return analogRead(m_nSensorPin);
}
cs