Moon and msp430

    Good day! I want to say right away that I am not campaigning for msp430, but since I bought it, I must apply it, as they say. Again, the community complained about the lack of specificity in posts about this platform. History, then, is the following. The task was set to purchase a night lamp in the bedroom. It is said that one must go to IKEA, there is one. But easy ways are not for us. The lamp was selected taking into account the subsequent possible modernization.
    So, the carcass:

    Originally imprisoned under the cartridge E14. But in a zashashnik a 5-meter LED strip was dusted for a long time. Cartridge - down. I glued the tape around the perimeter from the inside. The self-adhesive layer has dried up, but, thank God, it has stopped stinking badly. I had to use superglue. It turned out approximately the following:
    The emitter is ready. The control microcontroller selected the youngest of the msp430g2452 supplied with the Launchpad. I did not use the whole debug board. The big one hurts, and I laid my eyes on the controller, which is used in the programmer / emulator. I took a dead keychain from car alarms, cut a board for it from the wiring. I did not shoot the assembly process. The result is this: I
    ’ll explain a bit about the details.
    VT1 - a key that controls the IR LED;
    VT2 - Polevik switching LED strip;
    HL1 - IR - phototransistor;
    HL2 - IR - LED;
    HL3 - green LED;
    C1 - blocking electrolyte for power
    DA1 - 3.3V stabilizer. By the way, a small radiator is soldered to it.
    back side of the board:
    pieces of wire from bottom to right - debugging and programming connector. A debugger / programmer with a magic adapter is connected to it:
    Further on construction:
    The previously tested infrared distance sensor on the L-53F3C LED and the L-53P3C phototransistor was chosen as a non-contact sensor. I have dealt with this couple before. Built on them infrared bumpers for the robot. They have proven themselves well. The principle of operation of the sensor is simple. The processor first measures the voltage through the ADC on the phototransistor with the IR LED off. Then it turns on the IR LED and again measures the voltage at the phototransistor. The difference in measurements will depend on how strongly the surrounding objects reflect IR radiation. The closer the subject, the more reflected light enters the phototransistor. For reliability, I performed 3 measurements of each state. The result was averaged.
    Here is the switch in the case:
    Just doing on / off is not sports. For starters, made FadeIn and FadeOut. Those. smooth increase in brightness to maximum, and smooth shutdown. I used hardware PWM to adjust the brightness. Toward the close of the curtain, I added a function for manual brightness control. You hold your hand for a long time - the brightness gradually increases. Then it decreases.
    Source in the picture (it is necessary to unpack winrar) image

    Corrected source in the picture (see comments) image

    From the features of the program.
    We work with the ADC (measure the voltage on the photodiode);
    We work with timer0 (needed for hardware PWM, still blinking LED HL3);
    We do not work with WDT, although it would not be bad to escape from sudden hangs. Not yet observed, so did not touch.
    The exponential dependence of brightness-PWM is used, because a linear change in duty cycle does not lead to a linear change in brightness.
    Actually, the result of work:

    PS. I drew a diagram.

    Also popular now: