Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DOT 1 // DOT = 1 Si accende solo un led alla volta
- #define NUM_LEDS 9
- const byte led[NUM_LEDS] = { 4, 5, 6, 7, 8, 9, 10, 11, 12};
- void setup() {
- for(int i=0; i<NUM_LEDS; i++) {
- pinMode((const byte) led[i], OUTPUT);
- }
- Serial.begin(9600);
- }
- void loop() {
- vMeter();
- delay(100);
- }
- void vMeter(){
- volatile uint16_t leds;
- static uint8_t currentStep = 0;
- uint8_t newStep = map(analogRead(A0), 0, 1023, 0, NUM_LEDS);
- newStep = constrain(newStep, 0, NUM_LEDS);
- if(newStep != currentStep){
- if(currentStep - newStep > 0)
- currentStep -= 1;
- else
- currentStep += 1;
- }
- leds = 0;
- if(DOT == 0){
- for (int n=1; n<=NUM_LEDS ; n++) {
- if (currentStep >= n)
- bitClear(leds, n-1);
- }
- }
- else {
- for(int n=1; n<=NUM_LEDS ; n++) {
- if(currentStep >= n){
- bitClear(leds, n-1);
- if(n>1)
- bitSet(leds, n-2);
- }
- }
- }
- for(int i=0; i<NUM_LEDS; i++) {
- boolean isBitSet = leds & (1 << i);
- digitalWrite(led[i], isBitSet);
- }
- Serial.println(leds, BIN);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement