) Ko'ngil ochish uchun tezlik oralig'iga qarab rangni o'zgartiradigan bitta RGB LED qo'shildi




Download 0,91 Mb.
bet5/5
Sana19.07.2024
Hajmi0,91 Mb.
#267971
1   2   3   4   5
Bog'liq
INDIVIDUAL LOYIHA.. bekzod

6) Ko'ngil ochish uchun tezlik oralig'iga qarab rangni o'zgartiradigan bitta RGB LED qo'shildi.

Buning o'rniga yoki RGB LED-da, rasmda ko'rsatilgandek, barcha topraklama pinlarini qarshilikka ulash orqali oddiy 2 pinli LEDlardan foydalanish mumkin.

Kodi:

Kodi:

  • #include
  • #include
  • LiquidCrystal_I2C lcd(0x27,16,2); // Constructor for LCD, (Address of LCD, NoOfColumns,NoOfRows)
  • int ticks = 0, Speed = 0;
  • int hallsensor = 12; //The Hall effect sensor (HES) output of fan connected to pin no 12 of Arduino due
  • typedef struct{
  • char fantype;
  • unsigned int fandiv;
  • } fanspec;
  •  fanspec fanspace[3]={{0,1},{1,2},{2,8}}; char fan = 1; 
  • void pickrpm ()
  • { ticks++; }
  • void setup()
  • {
  • pinMode(hallsensor, INPUT);
  • Serial.begin(9600);
  • attachInterrupt(12, pickrpm, RISING);
  • analogWriteResolution(12);
  • lcd.init(); // initialize the lcd
  • lcd.backlight(); // backlight of lcd
  • lcd.home(); // initialize lcd cursor position
  • pinMode(9, OUTPUT);
  • pinMode(10, OUTPUT);
  • pinMode(11, OUTPUT);
  • digitalWrite(9, LOW);
  • digitalWrite(10, LOW);
  • digitalWrite(11, LOW);
  • }

void loop () {

  • void loop () {
  • ticks = 0; // Make ticks zero before starting interrupts.
  • interrupts(); // or use sei(); to Enables interrupts
  • delay (1000); //Wait 1 second
  • noInterrupts(); // or use cli(); to Disable interrupts
  •  Speed = ((ticks * 60)/fanspace[fan].fandiv);
  • Serial.print (Speed, DEC);
  • Serial.print (" RPM\r\n");
  • lcd.setCursor(2, 0); // (column,row)
  • lcd.print("Electromania");
  • lcd.setCursor(0, 1); // (column,row)
  • lcd.print("Speed:");
  • char SpeedString[4]; // Buffer to store string of 4 chars + 0 termination
  • sprintf(SpeedString, "%4d", Speed); // change this to %3, 4 ,5 etc depending upon your max speed
  • lcd.print(SpeedString);
  • lcd.print(" RPM");
  • if (Speed > 3000){
  • digitalWrite(9, HIGH);
  • digitalWrite(10, LOW);
  • digitalWrite(11, LOW); }
  • else if (Speed > 2000 && Speed < 3000){
  • digitalWrite(10, HIGH);
  • digitalWrite(9, LOW);
  • digitalWrite(11, LOW); }
  • else if (Speed > 1000 && Speed < 2000){
  • digitalWrite(11, HIGH);
  • digitalWrite(9, LOW); //red
  • digitalWrite(10, LOW); }
  • if (Speed > 0 && Speed < 1000){
  • digitalWrite(9, LOW); //red
  • digitalWrite(10, HIGH );
  • digitalWrite(11, HIGH); }
  • if (Speed == 0){
  • digitalWrite(9, LOW);
  • digitalWrite(10, LOW);
  • digitalWrite(11, LOW); }
  • } // end of loop function

E’tiboringgiz uchun rahmat!
Download 0,91 Mb.
1   2   3   4   5




Download 0,91 Mb.

Bosh sahifa
Aloqalar

    Bosh sahifa



) Ko'ngil ochish uchun tezlik oralig'iga qarab rangni o'zgartiradigan bitta RGB LED qo'shildi

Download 0,91 Mb.