2016-02-23 13:53:35 +01:00
|
|
|
/****************************************************************************
|
2021-06-16 09:22:16 +02:00
|
|
|
* apps/examples/rgbled/rgbled.c
|
2016-02-23 13:53:35 +01:00
|
|
|
*
|
2021-06-08 10:21:48 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2016-02-23 13:53:35 +01:00
|
|
|
*
|
2021-06-08 10:21:48 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-02-23 13:53:35 +01:00
|
|
|
*
|
2021-06-08 10:21:48 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-02-23 13:53:35 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2023-02-04 14:56:06 +01:00
|
|
|
|
2016-02-23 13:53:35 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2023-02-04 14:56:06 +01:00
|
|
|
#include <unistd.h>
|
2016-02-23 13:53:35 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-02-23 14:04:54 +01:00
|
|
|
#ifndef CONFIG_EXAMPLES_RGBLED_DEVNAME
|
|
|
|
# define CONFIG_EXAMPLES_RGBLED_DEVNAME "/dev/rgbled0"
|
|
|
|
#endif
|
2016-02-23 13:53:35 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* rgbled_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
{
|
|
|
|
int red = 255;
|
|
|
|
int green = 0;
|
|
|
|
int blue = 0;
|
|
|
|
int sred = -1;
|
|
|
|
int sgreen = 1;
|
|
|
|
int sblue = 0;
|
|
|
|
int fd;
|
|
|
|
char buffer[8];
|
|
|
|
|
2016-02-23 14:04:54 +01:00
|
|
|
fd = open(CONFIG_EXAMPLES_RGBLED_DEVNAME, O_WRONLY);
|
2016-02-23 13:53:35 +01:00
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
2016-02-23 14:04:54 +01:00
|
|
|
printf("Error opening %s!\n", CONFIG_EXAMPLES_RGBLED_DEVNAME);
|
2016-02-23 13:53:35 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2023-02-04 14:56:06 +01:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
red += sred;
|
|
|
|
green += sgreen;
|
|
|
|
blue += sblue;
|
|
|
|
|
|
|
|
if (green == 255)
|
|
|
|
{
|
|
|
|
sred = 0;
|
|
|
|
sgreen = -1;
|
|
|
|
sblue = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blue == 255)
|
|
|
|
{
|
|
|
|
sred = 1;
|
|
|
|
sgreen = 0;
|
|
|
|
sblue = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (red == 255)
|
|
|
|
{
|
|
|
|
sred = -1;
|
|
|
|
sblue = 0;
|
|
|
|
sgreen = 1;
|
|
|
|
}
|
|
|
|
|
2023-03-05 16:55:15 +01:00
|
|
|
snprintf(buffer, sizeof(buffer), "#%02X%02X%02X", red, green, blue);
|
2023-02-04 14:56:06 +01:00
|
|
|
write(fd, buffer, 8);
|
|
|
|
usleep(5000);
|
|
|
|
}
|
2016-02-23 13:53:35 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|