使用arduino的led灯光秀

时间:2016-09-04 22:43:02

标签: arduino

sketch_Show_The_Hat.ino:77:5: error: expected declaration before ‘}’ token

有些人可以帮忙找出这个错误的来源吗?

这是我的代码:

#include "LPD8806.h"
#include "SPI.h"



//#define HOLIDAY_MODE

#define MOMENTARY_SWITCH



// Example to control LPD8806-based RGB LED Modules in a strip!



int dataPin = 2;

int clockPin = 3;

int onOffPin = 4;



// Set the first variable to the NUMBER of pixels. 32 = 32 pixels in a row

// The LED strips are 32 LEDs per meter but you can extend/cut the strip

LPD8806 strip = LPD8806(32, dataPin, clockPin);



  void setup() {

  // Start up the LED strip

  strip.begin();



  // Update the strip, to start they are all 'off'

  strip.show();

  randomSeed(analogRead(A0));



  // On/Off switch

  pinMode(onOffPin, INPUT_PULLUP);

  }



int x = 0;

int dim = 0;

#ifdef MOMENTARY_SWITCH

int tdim = 0;

#endif



void loop();

  int r, g, b, y, z;



  #ifdef MOMENTARY_SWITCH

}  if (digitalRead(onOffPin) == LOW) {

    if ((dim == 0) && (tdim == 0) 

      tdim = !0;

    } else if ((dim == 128) && (tdim != 0)) 

      tdim = 0;




  if (tdim) {

    if (dim < 128) {

      dim++;



  } else {


  }

    if (dim > 0) {

      dim--;


      }

  } if (digitalRead(onOffPin) == LOW) {


    }

  }   

  } if (dim < 128) {

      dim++;



  } else {

    if (dim > 0) {

      dim--;

    }

  }

  #endif



  for (int i = 0; i < strip.numPixels(); i++) {

    y = (x + (i << 5)) & 511;

    #ifdef HOLIDAY_MODE

    // Holiday

    if (y >= 256) {

      y = 511 - y;

    }

    z = 255 - y;

    r = (y <= 128) ? (y - 128) << 1 : 0;

    g = (z <= 128) ? (z - 128) << 1 : 0;

    b = 0;

    # else

    // Normal

    if (y < 128) {

      r = y;

      g = 0;

      b = 255 - y;

    } else if (y < 256) {

      r = 127;

      g = y - 128;

      b = 0;

    } else if (y < 384) {

      r = 127;

      g = 127 - (y - 256);

      b = 0;

    } else {

      r = 127 - (y - 384);

      g = 0;

      b = y - 384;

    }

    #endif

    if (dim == 0) {

      r = 0;

      g = 0;

      b = 0;

    } else if (dim < 128) {

      r = (r * dim) / 128;

      g = (g * dim) / 128;

      b = (b * dim) / 128;

    }

    strip.setPixelColor(i, r & 127, g & 127, b & 127);

  }

  strip.show();

  x += 2;

  x &= 511;

  delay(5);



//    for(int j=0; j < random(100,200); j++ ) {

//      int i = random(0,strip.numPixels()-2) + 1;

//      strip.setPixelColor(i-1, 43,54,219);

//      strip.setPixelColor(i, 255,255,0);

//      strip.setPixelColor(i+1, 255,69,0);

//      strip.setPixelColor(i-1, 0,0,255);

//      strip.setPixelColor(i, 255,0,0);

//      strip.setPixelColor(i+1, 0,255,0);

//      strip.show();

//      delay(5);    

//      strip.setPixelColor(i-1, 255,128,0);

//      strip.setPixelColor(i-4, 255,128,0);

//      strip.setPixelColor(i+1, 4,0,8);

//      strip.setPixelColor(i-4, 104,10,80);

//      strip.setPixelColor(i-10, 43,54,219);

//      strip.setPixelColor(i-30, 255,165,0);

//      strip.setPixelColor(i+5, 219,125,45);

//      strip.setPixelColor(i, 100,100,127);

//      strip.setPixelColor(i+1, 104,100,198);

//      strip.show();

//      delay(1);

//      strip.setPixelColor(i+32, 219,112,147);

//       

//      strip.setPixelColor(i+1, 255,69,0);

//      strip.setPixelColor(i-2, 255,127,75);

//      strip.setPixelColor(i-6, 255,69,0);

//      strip.setPixelColor(i+5, 255,128,0);

//      strip.setPixelColor(i+2, 10,227,100);

//      strip.show();

//      delay(0);

//      strip.setPixelColor(i-1, 255,69,0);

//      strip.setPixelColor(i, 255,69,0);

//      strip.setPixelColor(i-6, 255,69,0);

//      strip.setPixelColor(i-6, 255,69,0);

//      strip.setPixelColor(i-6, 255,69,0);

//      strip.setPixelColor(i-12, 148,0,211);

//      strip.setPixelColor(i-6, 255,69,0);

//      strip.setPixelColor(i-3, 148,0,211);

//      strip.setPixelColor(i-1, 148,0,211);

//      strip.setPixelColor(i-6, 255,69,0);

//      strip.setPixelColor(i+2, 148,0,211);

//      strip.show();

//      delay(random(10,100));

//    }

//    for(int j=0; j < random(10,15); j++ ) {

//      for (int i=32; i < strip.numPixels(); i++) {

//        strip.setPixelColor(i, 0,0,255);

//      }

//      strip.show();

//      delay(15);

//      for (int i=2; i < strip.numPixels(); i++) {

//        strip.setPixelColor(i, 255,110,0);

//      }

//      strip.show();

//      delay(15);



 //    }

1 个答案:

答案 0 :(得分:-1)

首先,我通过编辑更正了您的格式。错误是在77.第5行中表示与}字符有关的错误。错误是你没有在{之前宣布任何}

当我尝试更正您的格式时(在我的文件版本上)77。line是一个空行。但问题可能出在76. line } if (digitalRead(onOffPin) == LOW) {,所以请尝试删除{字符。我的意思是尝试用if (digitalRead(onOffPin) == LOW) {替换该行,让我们看看错误是否仍然存在。

大括号: https://www.arduino.cc/en/reference/braces

提醒:在提问时请务必注意StackOverflow上的格式。格式化文本尤其是问题是正确交换知识的关键。在这里共享您的一个代码文件时,格式化是必要的。因为如果你没有格式化你的文本(实际上是你的代码),我们就无法测试它们。