Skip to content

Commit

Permalink
Add an example Bargraph with Pot
Browse files Browse the repository at this point in the history
Add an example Bargraph with Pot
  • Loading branch information
DogushC committed Apr 17, 2023
1 parent de9126f commit 3467aa1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Binary file added BargraphwPot/BargraphwPot.fzz
Binary file not shown.
43 changes: 43 additions & 0 deletions BargraphwPot/BargraphwPot.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* BargraphwPot
# Maintainer & Author
Maintainer: Turkish Technology Team (T3) Foundation (https://deneyapkart.org/)
Author: Dogus Cendek (https://github.com/DogushC)
# Description
Read potentiometer and display value an Bargraph.
# Hardware Components
1 x Deneyap Kart
1 x Bargraph
1 x Potentiometer
1 x Breadboard
1 x Micro-B USB Cable
*/

/*Pins for potentiometer and bargraph*/
const int potPin = A0; //the pin that the potentiometer is attached to
int ledPins[] = {D0, D1, D4, D5, D6, D7, D9, D10, D11, D12}; //an array of pin numbers to which LEDs of Bargraph

const int ledCount = 10; //the number of LEDs in the bar graph

void setup() {
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
}
}

void loop() {
int potValue = analogRead(potPin);
int ledLevel = map(potValue, 0, 4095, 0, ledCount); //map the result to a range from 0 to the number of LEDs

/*loop over the LED array*/
for (int j = 0; j < ledCount; j++) {
if (j < ledLevel) {
digitalWrite(ledPins[j], HIGH);
}
else {
digitalWrite(ledPins[j], LOW);
}
}
}
Binary file added BargraphwPot/BargraphwPot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3467aa1

Please sign in to comment.