【问题标题】:What is an algorithm for displaying rpm on set of LEDs?在一组 LED 上显示 rpm 的算法是什么?
【发布时间】:2022-07-13 00:10:41
【问题描述】:

所以我有一个 Arduino 正在读取我车上的转速。我还有一个连接到 Arduino 的 15 像素新像素条。

我想让 Arduino 做的是让 LED 灯条显示 rpm。随着 rpm 的增加,从灯条左侧开始亮起的 LED 数量增加。

我坚持并希望得到帮助的是,我不仅希望 LED 根据 rpm 打开或关闭,还希望改变亮度。

例如,假设转速为 2000,因此像素 4(将由公式计算的任意数)是要打开的顶部像素。现在随着 rpm 的增加,像素 5 的亮度将从 0 增加到 255。然后像素 6 的亮度将增加等等,从而在像素之间创建平滑过渡。

所以我需要帮助的是能够输入 rpm 并输出顶部像素及其亮度。从那里我将能够只填充顶部像素下方的 LED。

我希望最高转速为 8000。

如果您需要更多信息,请告诉我。谢谢!

【问题讨论】:

    标签: algorithm arduino neopixel


    【解决方案1】:

    这段代码有帮助吗?这具有计算最后一个像素的代码 - 以及该像素的亮度。

    #define NUM_LEDS 15
    #define NUM_BRIGHTNESS_LEVELS 256
    #define MAX_REVS 8000
    
    void setup()
    {
      Serial.begin(9600); 
    }
    
    void loop()
    {
        for ( int revs = 0 ; revs <= MAX_REVS ; revs += 500 )
        {
          int totalBrightness = ((float)revs / MAX_REVS) * (NUM_LEDS * NUM_BRIGHTNESS_LEVELS);
          int lastPixel = (totalBrightness / NUM_BRIGHTNESS_LEVELS); 
          int brightness = totalBrightness % NUM_BRIGHTNESS_LEVELS; 
    
          if ( lastPixel >= NUM_LEDS )
          {
            lastPixel = NUM_LEDS - 1; 
            brightness = NUM_BRIGHTNESS_LEVELS - 1; 
          }
    
          Serial.print("revs = ");
          Serial.print(revs);
          Serial.print(", pixel = ");
          Serial.print(lastPixel);
          Serial.print(", brightness = ");
          Serial.println(brightness); 
          
          delay(100); 
        }
        delay(2000);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-26
      • 2011-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-20
      • 2017-12-07
      相关资源
      最近更新 更多