Showing posts with label LED. Show all posts
Showing posts with label LED. Show all posts

LED ON OFF For One Sec/Count and Display on the Attached Serial Monitor

Turns on an LED on for one second, then off for one second, repeatedly. Counts and displays the count on the attached serial monitor

  1. /* Sketch uses 13,808 bytes (12%) of program storage space. Maximum is 108,000 bytes.
  2.    Global variables use 2,592 bytes of dynamic memory.
  3.   Turns on an LED on for one second, then off for one second, repeatedly.
  4.   Counts and displays the count on the attached serial monitor
  5.  */
  6. int n = 0;
  7. void setup() {                
  8.   // initialize the digital pin as an output.
  9.   pinMode(33, OUTPUT);
  10.   // Initialize virtual COM over USB on Maple Mini
  11.   Serial.begin(9600);  // BAUD has no effect on USB serial: placeholder for physical UART
  12.   // wait for serial monitor to be connected.
  13.   while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
  14.   {
  15.     digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
  16.     delay(100);         // fast blink
  17.   }
  18.   Serial.println("Blink LED & count Demo");
  19. }
  20. void loop() {
  21.   digitalWrite(33, HIGH);   // set the LED on
  22.   //delay(5);              // wait for a second
  23.   digitalWrite(33, LOW);    // set the LED off
  24.   Serial.print("Loop #: ");
  25.   n++;
  26.   Serial.println(n);
  27.    
  28.   //delay(5);              // wait
  29. }

Pushbutton LED Code in C

Pushbutton LED Code in C


intbuttonState = 0;
void setup() {
 // initialize the LED pin as an output:
pinMode(13, OUTPUT);
 // initialize the pushbutton pin as an input:
pinMode(11, INPUT);
}
void loop() {
 // read the state of the pushbutton value:
buttonState = digitalRead(11);
 // check if the pushbutton is pressed.
 // if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
 // turn LED on:
digitalWrite(13, HIGH);
 } else {
 // turn LED off:
digitalWrite(13, LOW);
 }
}