728x90
반응형
/* Get input and turn the LED on and off */
const int LED = 10;
void setup(){
Serial.begin(115200);
pinMode(LED, OUTPUT);
}
void loop(){
if(Serial.available()){
char userInput = Serial.read();
switch(userInput){
case 'n':
digitalWrite(LED, HIGH);
break;
case 'f':
digitalWrite(LED, LOW);
break;
default:
break;
}
}
}
// Adjust the LED brightness
const int LED = 10;
void setup(){
Serial.begin(115200);
}
void loop(){
if (Serial.available()){
char userInput = Serial.read();
switch(userInput){
case '0': analogWrite(LED, 0); break;
case '1': analogWrite(LED, 25 * 1); break;
case '2': analogWrite(LED, 25 * 2); break;
case '3': analogWrite(LED, 25 * 3); break;
case '4': analogWrite(LED, 25 * 4); break;
case '5': analogWrite(LED, 25 * 5); break;
case '6': analogWrite(LED, 25 * 6); break;
case '7': analogWrite(LED, 25 * 7); break;
case '8': analogWrite(LED, 25 * 8); break;
case '9': analogWrite(LED, 25 * 9); break;
default: break;
}
}
}
const int digitalPin = 2;
void setup(){
Serial.begin(115200);
pinMode(digitalPin, INPUT);
}
void loop(){
int digitalValue = digitalRead(digitalPin);
Serial.println(digitalValue);
}
// from 2 to 5v = Print on the Serialmonitor (1)
// from 2 to gnd = Print on the Serialmonitor (0)
const int digitalPin = 2;
void setup(){
Serial.begin(115200);
pinMode(digitalPin, INPUT);
}
void loop(){
int digitalValue = digitalRead(digitalPin);
Serial.println(digitalValue);
}
// print '0' on the SerialMonitor
// if push button Changing ouput value '1'
const int ledPin = 13;
const int buttonPin = 2;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
int buttonInput = digitalRead(buttonPin);
digitalWrite(ledPin, buttonInput);
}
// Turn on the LED when push Button
// faint bright depends on push the button
const int ledPin = 10;
const int buttonPin = 2;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
int buttonInput = digitalRead(buttonPin);
if(buttonInput == HIGH)
{
for(int t_high=0; t_high<=255; t_high++)
{
analogWrite(ledPin, t_high);
delay(4);
}
}else {
analogWrite(ledPin, 0);
}
}
/* Make the LED Dice */
const int led[6] = { 3, 5, 6, 9, 10, 11 };
const int buttonPin = 2;
void setup()
{
for(int x=0;x<=5;x++)
{
pinMode(led[x], OUTPUT);
}
pinMode(buttonPin, INPUT);
}
void loop()
{
int buttonInput = digitalRead(buttonPin);
if(buttonInput == HIGH)
{
for(int x=0;x<=5;x++)
{
for(int x=0;x<=5;x++)
{
digitalWrite(led[x], LOW);
}
digitalWrite(led[x], HIGH);
buttonInput = digitalRead(buttonPin);
if(buttonInput == LOW) break;
delay(50);
}
}
}
728x90
반응형
'Firmware & Embedded > AVR' 카테고리의 다른 글
attachInterrupt (0) | 2022.09.22 |
---|---|
PWM - Timer Library (0) | 2022.09.22 |
Analogue Read (0) | 2022.09.21 |
Basic Arduino (by circuit) (0) | 2022.09.21 |
Check the built-in LED using Arduino IDE (0) | 2022.09.20 |