Home

Thursday, September 25, 2014

push LED

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;

int sw = 8;

boolean sw000 = HIGH;
int ledStatus = 0;


void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
 
  pinMode(sw, INPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
  int swInput = debounceSwitch(sw, sw000);
  if((swInput == HIGH) && (sw000 == LOW)) {
    //กำหนดสถานะ led
    ledStatus = ledStatus +1;
    if (ledStatus > 4)ledStatus = 0;
   
}
sw000 = swInput;
if (ledStatus == 0){
  ledOutput(LOW,LOW,LOW,LOW);
}  else if (ledStatus == 1){
  ledOutput(LOW,LOW,LOW,HIGH);
}  else if (ledStatus == 2) {
  ledOutput(LOW,LOW,HIGH,HIGH);
} else if (ledStatus == 3) {
  ledOutput(LOW,HIGH,HIGH,HIGH);
} else {
  ledOutput(HIGH,HIGH,HIGH,HIGH);
}
}


void ledOutput (int ledVal1, int ledVal2, int ledVal3, int ledVal4) {
  digitalWrite (led1,ledVal1);
  digitalWrite (led2,ledVal2);
  digitalWrite (led3,ledVal3);
  digitalWrite (led4,ledVal4);
}

boolean debounceSwitch(int swPin, boolean LastLogic) {
  boolean currentLogic = digitalRead (swPin);
  if (currentLogic != LastLogic) {
    delay(2);
    currentLogic = digitalRead(swPin);
  }
  return currentLogic;
}

LED uno

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;

int sw = 8;

boolean sw000 = HIGH;
int ledStatus = 0;


void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
 
  pinMode(sw, INPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
  int swInput = debounceSwitch(sw, sw000);
  if((swInput == HIGH) && (sw000 == LOW)) {
    //กำหนดสถานะ led
    ledStatus = ledStatus +1;
    if (ledStatus > 3)ledStatus = 0;
   
}
sw000 = swInput;
}

void ledOutput (int ledVal1, int ledVal2, int ledVal3, int ledVal4) {
  digitalWrite (led1,ledVal1);
  digitalWrite (led2,ledVal2);
  digitalWrite (led3,ledVal3);
  digitalWrite (led4,ledVal4);
}

boolean debounceSwitch(int swPin, boolean LastLogic) {
  boolean currentLogic = digitalRead (swPin);
  if (currentLogic != LastLogic) {
    delay(2);
    currentLogic = digitalRead(swPin);
  }
  return currentLogic;
}
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;

int sw = 8;

boolean sw000 = HIGH;


void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
 
  pinMode(sw, INPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
  int swInput = digitalRead(sw);
  if (swInput == HIGH){
    ledOutput(HIGH,HIGH,HIGH,HIGH);
  } else {
    ledOutput(LOW,LOW,LOW,LOW);
  }
}

void ledOutput (int ledVal1, int ledVal2, int ledVal3, int ledVal4) {
  digitalWrite (led1,ledVal1);
  digitalWrite (led2,ledVal2);
  digitalWrite (led3,ledVal3);
  digitalWrite (led4,ledVal4);
}

boolean debounceSwitch(int swPin, boolean LastLogic) {
  boolean currentLogic = digitalRead (swPin);
  if (currentLogic != LastLogic) {
    delay(2);
    currentLogic = digitalRead(swPin);
  }
  return currentLogic;
}

Switch UNO

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;

int sw = 8;
void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
 
  pinMode(sw, INPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
  int swInput = digitalRead(sw);
  if (swInput == HIGH){
    ledOutput(HIGH,HIGH,HIGH,HIGH);
  } else {
    ledOutput(LOW,LOW,LOW,LOW);
  }
}

void ledOutput (int ledVal1, int ledVal2, int ledVal3, int ledVal4) {
  digitalWrite (led1,ledVal1);
  digitalWrite (led2,ledVal2);
  digitalWrite (led3,ledVal3);
  digitalWrite (led4,ledVal4);
}

Arduino 25 Sep

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;

int sw = 8;
void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
 
  pinMode(sw, INPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
  ledOutput(LOW,HIGH,HIGH,LOW);
  delay(500);
  ledOutput(HIGH,LOW,LOW,HIGH);
  delay(500);
}

void ledOutput (int ledVal1, int ledVal2, int ledVal3, int ledVal4) {
  digitalWrite (led1,ledVal1);
  digitalWrite (led2,ledVal2);
  digitalWrite (led3,ledVal3);
  digitalWrite (led4,ledVal4);
}

Landing VTCC Chiang Mai Intl RWY36


Thursday, September 11, 2014

Arduino Code

int ledPin = 13;
int swPin = 8;
boolean X0 = LOW;
boolean X1 = HIGH;
boolean flagg = LOW;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  pinMode(swPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  X1=digitalRead(swPin);
  if ((X0 == LOW) && (X1==HIGH)) {
    flagg = !flagg;
  }
  X0=X1;
  digitalWrite(ledPin, flagg);
  }