HSV RGB IKEA lamp + IR Remote

November 12, 2013 2 comments

My first Awesome IKEA lamp had multiple trimmers and push buttons to setup speed, brightness and color. I now added a remote control to get rid of all these. I chose one of these common rgb remote controls that are shipped with every other cheap rgb lamp. I got it from dx.com. The led i use is a 3W rgb star led from ebay with the following specifications:

Red=2,4V, Green=3,4V, Blue=3,4V, 350mA per channel

Make sure you do not get one with common “+”; if so you can’t use p mosfets but must use the n version instead. Common ground is no problem. You’ll get a complete partlist from the eagle file. The main changes from the original layout are:

  • P_MOSFET: IRLML6402
  • IR-RECEIVER: TSOP 31238
  • IR_REMOTE: CR2025

hsvrgblamp1.0

I uploaded everything including the schematic, board and the code: Download!

The code is neither commented nor nice. Feel free to improve it ;-) There is a little problem with this version; the p-mosfets seem to have great leakage current so the leds wont turn off completely. I think the PORTD has to little output power…

Categories: Uncategorized

Awesome HSV RGB IKEA lamp

June 30, 2012 6 comments

When my girlfriend gave me her birthday present, i was overwhelmed. The drawing was perfect, I loved the motive, details and shadows. And it came that she had her own birthday! This was the moment i decided not to buy one of her wishlist’s entrys (yes i keep track) but build something by my own too (let’s just stick to buying things okay?). I thought about painting a picture too but decided against it. I just didn’t want to reveal my inner artist and make her jealous.

Since im a student of it and electronics, i chose to build something wired.  It had to be cool but also instructive for me i though. I always planned on building a “proper” RedGreenBlue LED Lamp which could fade between colors. But i never found the time nor the motivation to do something símilar in my freetime. The first attempts on my Arduino Board were pretty basic. The colors were fading, yes, but randomly which means (in RGB color space) pretty white changes to a white reddish to bright white reddish to a bright white reddish with a touch of green or blue. This wasn’t  that exciting at all. I “went” to the mikrocontroller.net community and asked about color spaces. My idea was to make a distinction between color and brightness and avoid same colors with just different portions of white. I found that the hsv (hue saturation value) color space met my needs. It allowed me to use a simple potentiometer for choosing the color (hue) and a further one for the brightness, while the saturation remains constant (no white parts please ;-))

I started coding (checkout github) the code for an atmega8 controller and tested it on a breadboard first. I found and bought a perfect fitting aluminium globe at IKEA which could hold both the led and the electronic circuit. Then I began with the final board layout in Eagle and ordered the other parts at reichelt: Three Potentiometers (two logarithmic ones), three nmos transistors, resistors, capacitors, push buttons, toggle and finally the power supply (5V2A).

I attached the parts to the new board and tested it with Georg who provided an oscillocope and even a 3D printer. I  designed and printed two plastic parts for the globe to hold the led and the board.

Also I changed the original design from a standing lamp to a laying one. I though it would look nicer and lighten a wall much better. Also the potentiometers and buttons were better accessible (It’s not a bug it’s a feature).

Everything looked fine but a random flashing which disturbed me. One user from the forum gave me hint that there could be something wrong with my code since he had the same problem in the past. So glad this guy read the post -> no flickering anymore!

During the project i learned a lot about the whole progress of implementing a vision. I really started with a vague idea and then made use of a great toolchain (3d printing, uC development, board layout in eagle, testing testing and testing with oscilloscope)… Also i must say that there were a lot of coincidences like a broken diode and a wrongly connected mosfet which i eventually hadn’t noticed in other places… Maybe you (Kenzie) remember that i was happy about the one day on skype? Yeah, i figured the board was actually working … so this was my last week; for you! be happy!

Looking forward to party in fading colors!

Reference:

https://github.com/kreuzUndQwertz/hsv2rgb (code and board layouts as well as the openscad 3d designs)

http://www.mikrocontroller.net/topic/262143#postform (thread on rgb space and flashing issue)

Categories: electronics, Uncategorized

Ratelet a OSX Menulet to control iTunes’ rating and volume

May 23, 2012 Leave a comment

Hey, i finally submitted my first official App to the Apple App Store! Check it out ;-)

Ratelet is shown in your statusbar and gives you easy access to the rating of the current song and iTunes volume.

Ratelet will automatically hide itself from the statusbar when iTunes is not running and reveal if iTunes starts. You can hide the volume slider if you only need the rating bar.

Quickly changing iTunes volume can be useful especially when you use Airplay or output sound digital because the Mac’s volume buttons only affect analog output volume!

 

 

 

 

Anchor Point vs. Position (CALayer)

April 3, 2012 1 comment

Yesterday i was trying to do some animation which included rotation along the x axis. For this i needed to figure out how to set the anchor point of my layer without moving it in the superlayers coordinate system. But when i setted a different anchor Point the layer moved.
I didn’t know why and some internet resources did not help me at all.

I noticed that both setting the position or the anchor point would move the layer. But setting the one does not affect the other. Some pages on the web explained this bahvior with examples. Now i will give you an example too but no instrutions or advices for how to work with it in concrete cases. This post tries to explain the concept in general.

The anchor point is an attribute of every layer. Its coordinates describe a realtive position in your layer. Every point from 0.0/0.0 to 1.0/1.0 describes a point withing the bounds of the layer. Every negative pair like -1.0/-1.0 is placed once the height to the top and once the width to the left oustide the layers bounds. For instance 0.5/0.5 is the center of a layers bounds. Make sure you understand that this point is independent from the layers or superlayers actual dimension (in pixels or whatever). 0.5/0.5 always is the center independent from if its a layer of size 500×500 or 500×150.

Position on the other hand is expressed in actual layer dimensions but referrs to the superlayer not the layer itself! Position in short says “Position the layer in a way that the anchor point of the layer matches the position in my superlayer”.

Example: You have created a view (50×50) and added it to the center of your superview (150×150) using setCenter…
The anchor point of every layer is always set to 0.5/0.5 at creation time and therefor points to the center of the layer. Now when you added your view and placed it to the center, the position attribute of the layer makes shure that the layer is centered in respect to your anchor point (currently 0.5/0.5).

Since the anchor point is the center of the sublayer, the position attribute must be the center of the super layer so that the layers center is the superlayers center. As stated above, the position attribute now says “the layer is positioned in a way that the relative point 0.5/0.5 (anchor point) is at the super views center by setting the position to 75×75 sublayer.

20120403-154128.jpg

Now imagine you change the anchor point so that not the layers center is centered in the superlayer but the upperleft corner. All you need to do is setting the anchor point to 0.0/0.0 which represents the realtive position for the upper left corner.
20120403-154201.jpg

NSStatusItem highlight custom Button workaround!

March 30, 2012 Leave a comment

I’m building a Menulet with multiple buttons. Since these buttons do no inherit the default behavior of getting blue when clicked, i searched for a quick solution. Since i don’t know how to implement a custom cell and had no ambition to do so, i finally found a nice and quick solution.

The following lines make shure the button won’t show a white background which is default for every buttonType but NSMomentaryChangeButton.

  1. //make sure button won’t show the “alternateImage” when selected
  2. [configureItem setButtonType:NSMomentaryChangeButton];
  3. [configureItem setBezelStyle:NSRegularSquareBezelStyle];
  4. [configureItem setBordered:NO];

Then the next few lines are called in the MenuItem’s delegate every time the menu will open or close.

  1. #pragma mark menu delegate
  2. - (void)menuWillOpen:(NSMenu *)menu {
  3.         [[configureItem cell] setBackgroundColor:[NSColor selectedMenuItemColor]];
  4. }
  5. -(void)menuDidClose:(NSMenu *)menu {
  6.         [[configureItem cell] setBackgroundColor:[NSColor clearColor]];
  7.     [menu release];
  8. }

Menulet for iTunes volume

January 30, 2012 Leave a comment

Menulet to control iTunes volume

Just needed a quick access to control uatunes volume since this also applies to the airplay volume. Here’s a small Menulet which offers a slider to control it. Have fun ;-)

Download/a>

I used the ScriptingBridge and this article to build the app!

Solution: UIScrollview that doesn’t interfere with content touches

December 14, 2011 3 comments

Hi there, i’m currently working on a drawing-application which uses a scrollview to navigate threw the content. With the normal UIScrollview you will definitely run into problems!

The problem is that UIScrollView will only deliver taps but no movement gestures to it’s content.

1) So i was looking for a solution to pan and zoom with 2 fingers and interact with the content-view with one finger.

2) Also it should be possible to have a period of time in which the 1 finger touch event can be canceled by the two finger events. This is useful since people tend to start with one finger followed by the second one a little later.

3)Also it should be possible to touch the screen with a second finger without canceling the content interaction!

The idea was to filter all the touch-events, but since UIScrollView uses gesture recognizers (namely UIScrollViewPanGestureRecognizer which inherits from UIPanGestureRecognizer) you can’t filter these touches since there aren’t any but the first touchesBegan…

To solve these problems i did the following:

  1. Set setCanCancelContentTouches:NO when you detect a 1 touch event in touchesBegan: works but you still have the problem with 2).
    • Solution: Use a timer to set setCanCancelContentTouches:NO after a period like 0.1 seconds or so
      • Problem: In the first moments the gesture recognizer will interfere with your touch movements and use them instead
        • Solution: Reconfigure all pangesture recognizers to only accept 2 touch events
Note that i check the gesture recognizers against isKindOfClass not isMemberOfClass since UIScrollViewPanGestureRecognizer inherits from UIPanGestureRecognizer.
Also dont worry about touchFilter! This is the contentview, which in fact doesn’t filter the touches but uses the prefiltered ones!
When the user starts with a one finger gesture and (before timer fired) continues with a second one, beganTouches: and canceledTouches: will be called in this order. The number of touches in canceledTouches will therefore be 2; your contentview must be aware of this, cause if it ignores two touch events it won’t get the canceled event which could result in quite strange behavior.
  1. #import “JWTwoFingerScrollView.h”
  2. @implementation JWTwoFingerScrollView
  3. #pragma mark -
  4. #pragma mark Event Passing
  5. - (id)initWithCoder:(NSCoder *)coder {
  6. self = [super initWithCoder:coder];
  7. if (self) {
  8. for (UIGestureRecognizer* r in self.gestureRecognizers) {
  9. NSLog(@“%@”,[r class]);
  10. if ([r isKindOfClass:[UIPanGestureRecognizer class]]) {
  11. [((UIPanGestureRecognizer*)r) setMaximumNumberOfTouches:2];
  12. [((UIPanGestureRecognizer*)r) setMinimumNumberOfTouches:2];
  13. }
  14. }
  15. }
  16. return self;
  17. }
  18. -(void)firstTouchTimerFired:(NSTimer*)timer {
  19. [self setCanCancelContentTouches:NO];
  20. }
  21. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  22. [self setCanCancelContentTouches:YES];
  23. if ([event allTouches].count == 1){
  24. touchesBeganTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(firstTouchTimerFired:) userInfo:nil repeats:NO];
  25. [touchesBeganTimer retain];
  26. [touchFilter touchesBegan:touches withEvent:event];
  27. }
  28. }
  29. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  30. [touchFilter touchesMoved:touches withEvent:event];
  31. }
  32. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  33. NSLog(@“ended %i”,[event allTouches].count);
  34. [touchFilter touchesEnded:touches withEvent:event];
  35. }
  36. -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
  37. NSLog(@“canceled %i”,[event allTouches].count);
  38. [touchFilter touchesCancelled:touches withEvent:event];
  39. }

It really took me ages to get this running, there were plenty other solutions which all didnt meet my needs. Some used a timer but delayed the first touch event, others allowed only one touch event but interrupted as soon as there was a two finger touch event. Some threads on stackoverflow might be interesting for you, since it also helped me to get this solution working!

http://stackoverflow.com/questions/787212/scrolling-with-two-fingers-with-a-uiscrollview

if you want, download  the files!

Follow

Get every new post delivered to your Inbox.