2015年7月23日 星期四

Arduino using PWM Controlled a Fan

//Arduino Fan Control

//  * SoftwarePWM.pde
const int pin = 3;
boolean Q=1;
void setup()
{
  pinMode(pin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  if (Q) {
    FullRun();
  }

 int sensorValue = analogRead(A0);
 int sensor1 = map(sensorValue, 0, 1023, 0 ,255);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.print("Analog VR Read: ");
  Serial.print(sensor1);
  Serial.print("   Voltage:  Analoag Read * (5.0 / 1023.0)= ");
  Serial.println(voltage);

  analogWrite(pin, sensor1);
 }
//==========================================

void FullRun() {
analogWrite(pin, 255);
delay(1500);
Q=0;
}
//==========================================





沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) 3) 使用database需先create建立資料庫 Node-Red 程式 [...