// // hello.D11C.echo.ino // // D11C USB echo hello-world // // Neil Gershenfeld 11/29/19 // Modified by Seung Hyeon 10/7/22 with the help of Anthony (HTMAA 2022 Instructor) // // This work may be reproduced, modified, distributed, // performed, and displayed for any purpose, but must // acknowledge this project. Copyright is retained and // must be preserved. The work is provided as is; no // warranty is provided, and users accept all liability. // #define LED1 4 #define LED2 8 #define button 2 void setup() { SerialUSB.begin(0); //making LED outputs pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(button, INPUT_PULLUP); //pull up resistor-10k } #define max_buffer 25 //making a variable int count = 0; int current_state = 1; int previous_state = 1; void loop() { //Seung Hyeon's code for LED on/off switch if (digitalRead(button)==LOW && count==0 && previous_state==1){ //when you press the button and make the voltage grounded, it's equal to LOW digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); count = 1; previous_state = 0; current_state = 0; //of the buttons } //delay(2000); //giving delay time for the button press (but poor timing) if (digitalRead(button)==LOW && count==1 && previous_state==1){ digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); count = 0; previous_state = 0; current_state = 0; } //delay(2000); //giving delay time for the button press if (digitalRead(button)==HIGH){ previous_state = current_state; current_state = 1; } // Serial.println(count); // Neil's code for echo static char chr; static char buffer[max_buffer] = {0}; //array of zeros static int index; if (SerialUSB.available()) { chr = SerialUSB.read(); SerialUSB.print("hello.D11C.echo: you typed \""); buffer[index++] = chr; if (index == (max_buffer-1)) index = 0; SerialUSB.print(buffer); SerialUSB.println("\""); } }