Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

Πως να αναβοσβήσετε τα LEDs

25/3/2018

Comments

 

Εισαγωγή

Αναβοσβήστε τα LED ξεχωριστά και ρυθμίστε τον χρόνο αλλαγής με δύο κουμπιά. Εκτυπώστε το χρόνο διαστήματος στην οθόνη LCD.

Τα υλικά που θα χρειαστούμε:

Θα χρησιμοποιήσουμε:
  • 3x 5mm LED
  • 2x κουμπιά
  • Nokia 5110 LCD

Συνδέσεις

LEDs και κουμπιά
  • Arduino UNO pin 9 --> LED1
  • Arduino UNO pin 10  --> LED2
  • Arduino UNO pin 11 --> LED3
  • Arduino UNO pin 8 --> Κουμπί 1
  • Arduino UNO pin 12 --> Κουμπί 2



Nokia 5110 LCD (Μπλέ PCB)
  • Arduino UNO pin 3 --> CLK
  • Arduino UNO pin 4 --> Din
  • Arduino UNO pin 5 --> DC
  • Arduino UNO pin 6 --> CE
  • Arduino UNO pin 7 --> RST

Κώδικας

  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
/*
 * === Ardumotive Shield for Arduino UNO Board ===
 * Arduino Tutorial: Blink LEDs - Control the changing interval with buttons 
 * Dev Michalis Vasilakis/Date 24/3/2018/http://ardumotive.com
 */
 
#define pinLED1 9
#define pinLED2 10
#define pinLED3 11
#define bt1 8
#define bt2 12

#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display = Adafruit_PCD8544(3,4,5,6,7);

unsigned long previousMillis = 0;
float interval=0.5; //ms
int select=1;

void setup() {
  // Put your setup code here, to run once:
  // Define LED pins as outputs and buttons as INPUT_PULLUP:
  pinMode(pinLED1, OUTPUT);
  pinMode(pinLED2, OUTPUT);
  pinMode(pinLED3, OUTPUT);
  pinMode(bt1,INPUT_PULLUP);
  pinMode(bt2,INPUT_PULLUP);
  
  display.begin();
  display.setContrast(50);
  display.clearDisplay();   // clears the screen and buffer
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(bt1)==0){
    delay(250);
    interval = interval + 0.1;
  }
  if (digitalRead(bt2)==0){
    delay(250);
    interval = interval - 0.1;
  }
  display.setTextSize(1);
  display.println("Interval:");
  display.println("");
  display.setTextSize(3);
  display.println(interval);
  display.display();
  
  blinkAll(interval);
  //blinkSeparate(interval);
  
  display.clearDisplay();   // clears the screen and buffer

}

boolean flag=false;

void blinkAll(float interval){
  interval = interval * 1000;
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    if (flag){
      digitalWrite(pinLED1, HIGH);
      digitalWrite(pinLED2, HIGH);
      digitalWrite(pinLED3, HIGH);
      flag=false;
    }
    else{
      digitalWrite(pinLED1, LOW);
      digitalWrite(pinLED2, LOW);
      digitalWrite(pinLED3, LOW);
      flag=true;
    }
  }
}

void blinkSeparate(float interval){
  interval = interval * 1000;
  unsigned long currentMillis = millis();  
  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    if (select==1){
      digitalWrite(pinLED1, HIGH);
      digitalWrite(pinLED2, LOW);
      digitalWrite(pinLED3, LOW);
      select++;
    }
    else if (select==2){
      digitalWrite(pinLED1, LOW);
      digitalWrite(pinLED2, HIGH);
      digitalWrite(pinLED3, LOW);
      select++;
    }
    else if (select==3){
      digitalWrite(pinLED1, LOW);
      digitalWrite(pinLED2, LOW);
      digitalWrite(pinLED3, HIGH);
      select=1;
    } 
  }
}
Κατεβάστε τον κώδικα απ' εδώ και ανοίξτε το αρχείο με το Arduino IDE. Το αρχείο περιέχει και την βιβλιοθήκη που χρησιμοποιήσαμε.
ardumotive_shield_fade_leds.zip
File Size: 19 kb
File Type: zip
Download File

Comments
    Picture
    Picture

    License of this project:

    Picture

    Categories

    All
    1: Εισαγωγή
    2: Fade LEDs
    3: Blink LEDs
    4: Park Assist
    5: Temp-Hum-Brightness

    Help us to grow up!

    Picture




Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates