彩虹灯程序崩溃

rainbowview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
    NSArray*colorArr =@[[UIColor redColor],[UIColor orangeColor],[UIColor yellowColor],[UIColor greenColor],[UIColor blueColor],[UIColor cyanColor],[UIColor purpleColor]];
    for (int i = 0; i<7; i++) {
        UIView *rainbownil = [[UIView alloc] initWithFrame:CGRectMake(10+20*i, 50+20*i, 300-40*i, 500-40*i)];
        rainbownil.backgroundColor = colorArr[i];
        rainbownil.tag = 101+i;
        [rainbowview addSubview:rainbownil];
        [rainbownil release];
    }
    
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(exchangeColor) userInfo:self repeats:YES];
    
    
    
    
        
        
    
    [self.window addSubview:rainbowview];
    [rainbowview release];

//    [colorArr release];

最后一句,过度释放了,colorArr注释掉就好了



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的Arduino红外遥控按键控制彩虹程序: ``` #include <IRremote.h> // 引入红外遥控库 #include <Adafruit_NeoPixel.h> // 引入RGB LED带库 #define IR_PIN 2 // 红外接收器模块连接的引脚 #define LED_PIN 6 // RGB LED带连接的引脚 #define LED_COUNT 30 // RGB LED带的珠数量 IRrecv irrecv(IR_PIN); decode_results results; Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); void setup() { irrecv.enableIRIn(); // 启动红外接收器 strip.begin(); // 启动RGB LED带 strip.show(); // 显示光 } void loop() { if (irrecv.decode(&results)) { // 检测到遥控器信号 switch (results.value) { // 根据遥控器按键的值来判断执行哪种光效果 case 0xFF30CF: // 红色 colorWipe(strip.Color(255, 0, 0), 50); break; case 0xFF18E7: // 绿色 colorWipe(strip.Color(0, 255, 0), 50); break; case 0xFF7A85: // 蓝色 colorWipe(strip.Color(0, 0, 255), 50); break; case 0xFF10EF: // 闪烁 theaterChaseRainbow(50); break; case 0xFF38C7: // 呼吸 rainbowCycle(20); break; default: break; } irrecv.resume(); // 重置红外接收器 } } void colorWipe(uint32_t color, int wait) { for (int i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, color); strip.show(); delay(wait); } } void theaterChaseRainbow(int wait) { for (int j = 0; j < 256; j++) { for (int q = 0; q < 3; q++) { for (int i = 0; i < strip.numPixels(); i += 3) { strip.setPixelColor(i + q, Wheel((i + j) % 255)); } strip.show(); delay(wait); for (int i = 0; i < strip.numPixels(); i += 3) { strip.setPixelColor(i + q, 0); } } } } void rainbowCycle(int wait) { uint16_t i, j; for (j = 0; j < 256 * 5; j++) { for (i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); } } uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if (WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if (WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } ``` 这个程序使用了红外遥控库和RGB LED带库,其中`colorWipe()`函数用于实现颜色填充光效果,`theaterChaseRainbow()`函数用于实现彩虹闪烁光效果,`rainbowCycle()`函数用于实现彩虹呼吸光效果,`Wheel()`函数用于实现彩虹色彩的变化。当检测到遥控器信号时,程序会根据遥控器按键的值来判断执行哪种光效果。 希望这个程序能够帮助到您!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值