Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
2  leds/Makefile
@@ -332,7 +332,7 @@ $(TARGET).hex: $(TARGET).elf
332 332
 .INTERMEDIATE: $(TARGET).elf
333 333
 
334 334
 $(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
335  
-	$(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
  335
+	$(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -lm -o $@
336 336
 
337 337
 %.o: %.c
338 338
 	mkdir -p .dep/$(dir $<)
10  leds/lights.cpp
@@ -9,10 +9,14 @@ Lights::Lights() {
9 9
   }
10 10
 }
11 11
 
  12
+int logScale(int value) {
  13
+  return (int)((log(255 - value) / log(255)) * 255);
  14
+}
  15
+
12 16
 void Lights::set(int light, Colour colour) {
13  
-  analogWrite(LED_RED, 255-colour.red);
14  
-  analogWrite(LED_GREEN, 255-colour.green);
15  
-  analogWrite(LED_BLUE, 255-colour.blue);
  17
+  analogWrite(LED_RED, logScale(colour.red));
  18
+  analogWrite(LED_GREEN, logScale(colour.green));
  19
+  analogWrite(LED_BLUE, logScale(colour.blue));
16 20
   if (light == LED_RIGHT) {
17 21
     digitalWrite(LED_RIGHT, HIGH);
18 22
     digitalWrite(LED_LEFT, LOW);
25  leds/rgb_led.ino
@@ -2,13 +2,36 @@
2 2
 
3 3
 Lights lights;
4 4
 
  5
+void led_cycle(Lights *lights, int light, int time) {
  6
+  Colour c;
  7
+  char brightness = 128;
  8
+  float step = (2 * PI) / time;
  9
+  for (float i = 0; i < 2 * PI; i += step) {
  10
+    c.red = (int)(abs(sin(i)) * brightness);
  11
+    c.green = (int)(abs(sin(i + PI / 2)) * brightness);
  12
+    c.blue = (int)(abs(sin(i + PI)) * brightness);
  13
+    lights->set(light, c);
  14
+    delay(1);
  15
+  }
  16
+  c.red = 0; c.green = 0; c.blue = 0;
  17
+  lights->set(light, c);
  18
+}
  19
+
5 20
 void setup() {
  21
+  for (float i = 0; i < 2*PI; i += 0.01) {
  22
+    analogWrite(13, (int)(abs(sin(i)) * 255));
  23
+    delay(5);
  24
+  }
  25
+  led_cycle(&lights, LED_LEFT, 1000);
  26
+  led_cycle(&lights, LED_RIGHT, 1000);
6 27
 }
7 28
 
8 29
 void loop() {
  30
+
9 31
   Colour c;
10 32
   c.red=0;
11 33
   c.green=0;
12 34
   c.blue=0;
13  
-  lights.set(LED_LEFT, c);
  35
+  //
  36
+  //lights.set(LED_LEFT, c);
14 37
 }

No commit comments for this range

Something went wrong with that request. Please try again.