Created
May 10, 2015 06:56
-
-
Save ultramcu/f704973eeb901c058a2c to your computer and use it in GitHub Desktop.
Arduino Learing Why we use #define
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//GoodWriting 1.1 Preprocessive director -> #define | |
#include <stdint.h> | |
///* <----- 1 | |
//740,9 | |
#define LED_1 7 | |
#define LED_2 6 | |
#define LED_3 5 | |
#define LED_4 4 | |
//*/ | |
/* <----- 2 | |
//774,13 (13 - 9 = 4, 4/4 = 1) | |
uint8_t LED_1 = 7; | |
uint8_t LED_2 = 6; | |
uint8_t LED_3 = 5; | |
uint8_t LED_4 = 4; | |
//*/ | |
/* <----- 3 | |
//778,17 (17-9 = 8, 8/4 = 2) | |
int LED_1 = 7; | |
int LED_2 = 6; | |
int LED_3 = 5; | |
int LED_4 = 4; | |
//*/ | |
/* <----- 4 | |
//786,25 (25-9 = 16, 16/4 = 4) | |
long LED_1 = 7; | |
long LED_2 = 6; | |
long LED_3 = 5; | |
long LED_4 = 4; | |
//*/ | |
void setup() { | |
} | |
void loop() | |
{ | |
digitalWrite(LED_1,HIGH); | |
digitalWrite(LED_2,HIGH); | |
digitalWrite(LED_3,HIGH); | |
digitalWrite(LED_4,HIGH); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#define _DEBUG_ | |
#define LED_1 7 | |
#define LED_2 6 | |
#define LED_3 5 | |
#define LED_4 4 | |
void setup() | |
{ | |
#ifdef _DEBUG_ | |
Serial.begin(115200); | |
Serial.println("Hello, World."); | |
#endif | |
} | |
void loop() | |
{ | |
static uint8_t tg = 0; | |
if(tg == 0) | |
{ | |
digitalWrite(LED_1,HIGH); | |
digitalWrite(LED_2,HIGH); | |
digitalWrite(LED_3,HIGH); | |
digitalWrite(LED_4,HIGH); | |
#ifdef _DEBUG_ | |
Serial.println("All LED on !"); | |
#endif | |
} | |
else | |
{ | |
digitalWrite(LED_1,LOW); | |
digitalWrite(LED_2,LOW); | |
digitalWrite(LED_3,LOW); | |
digitalWrite(LED_4,LOW); | |
#ifdef _DEBUG_ | |
Serial.println("All LED off !"); | |
#endif | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment