int led = 14; // led pin
int but = 15; // button pin
int but_state = 1; // state of button
int prev_but = 1; // previous loop button state
int led_state = 0; // state of led
void setup() {
pinMode(led, OUTPUT);
pinMode(but, INPUT);
}
void loop() {
but_state = digitalRead(but); // read the button
// if the button was just pressed
if (but_state == 0 && prev_but == 1){
// toggle the led
if (led_state == 0){
led_state = 1;
}
else {
led_state = 0;
}
}
if (led_state == 1){
digitalWrite(led, HIGH);
}
else {
digitalWrite(led,LOW);
}
// remember the button state
prev_but = but_state;
}
int led = 14; // led pin
int but = 15; // button pin
volatile int led_state = 0; // variables used in intterupts must be declared volatile
void setup() {
pinMode(led, OUTPUT);
pinMode(but, INPUT);
// when but pin goes HIGH to LOW call the function but_pressed()
attachInterrupt(digitalPinToInterrupt(but), but_pressed, FALLING);
}
void loop() {
if (led_state == 1) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
}
void but_pressed() {
if (led_state == 1) {
led_state = 0;
}
else {
led_state = 1;
}
}
int led = 14; // led pin
void setup() {
Serial.begin(9600);
// configure LED PWM functionalitites
ledcSetup(0, 5000, 8); // ledChannel, freq, resolution
// attach the channel to the GPIO to be controlled
ledcAttachPin(led, 0); // ledPin, ledChannel
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
//analogWrite(led, sensorValue/16); // this is how most other Arduino work
ledcWrite(0, sensorValue/16); // ledChannel, dutyCycle
delay(10);
}
void setup() {
Serial.begin(115200); // use a faster baud when sending a lot of data fast
}
void loop() {
int sensorValues[1000]; // an array to store the data
int i = 0; // an index to remember where you are in the array
// get 1000 data points
for(i=0; i<1000; i++){
sensorValues[i] = analogRead(A0);
delayMicroseconds(10); // 10us delay = 100kHz sampling
}
// send the data to the computer
for(i=0; i<1000; i++){
Serial.println(sensorValues[i]);
}
// wait half a second so the user can see the plot
delay(500);
}