Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
void setup() { // put your setup code here, to run once: pinMode(LED_BUILTIN, OUTPUT); pinMode(2, INPUT_PULLUP); pinMode(4, INPUT_PULLUP); Serial.begin(9600); } float pwm = 50.00; // 50 % float period = 1000.0; // 1 seconds void loop() { // put your main code here, to run repeatedly: int buttonStateDown = digitalRead(4); int buttonStateUp = digitalRead(2); if (buttonStateDown == 0) { // Button is pressed pwm = pwm - 10; if (pwm < 0) pwm = 0.0; } if (buttonStateUp == 0) { // Button is pressed pwm = pwm + 10; if (pwm > 100) pwm = 100.0; } Serial.print("Down:"); Serial.print(buttonStateDown); Serial.print(" - Up:"); Serial.println(buttonStateUp); float on = pwm / 100 * period; float off = (100.0 - pwm) / 100 * period; digitalWrite(LED_BUILTIN, HIGH); delay(on); digitalWrite(LED_BUILTIN, LOW); delay(off); Serial.print(on); Serial.print("/"); Serial.print(off); Serial.print("/"); Serial.println(pwm); }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)