Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. RGB Servo spot

RGB Servo spot

Scheduled Pinned Locked Moved My Project
2 Posts 2 Posters 1.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • siklosiS Offline
    siklosiS Offline
    siklosi
    wrote on last edited by
    #1

    This is little project I made while ago but just now converted it to mysensors (used to be controlled via bluetooth)
    2_1454273523371_image1 (4).JPG 1_1454273523371_image2.PNG 0_1454273523370_image3 (1).JPG

    
    #include <MySensor.h>
    #include <SPI.h>
    #include <Servo.h>
    
    #define RED_PIN 3
    #define GREEN_PIN 5
    #define BLUE_PIN 6
    #define SERVO_H 7
    #define SERVO_V 8
    
    #define NODE_ID 5
    #define SERVO_RGB 0
    #define SKETCH_NAME "SERVO RGB"
    #define SKETCH_VERSION "1.0.0"
    #define NODE_REPEAT false
    #define FIRE_EFFECT 22
    
    Servo myservo_h;
    Servo myservo_v;
    MySensor gw;
    
    long RGB_values[3] = {0, 0, 0};
    float dimmer;
    //int r = 255;
    //int g = r - 80;
    //int b = 25;
    //int servh = 0;
    //int servv = 0;
    
    //MyMessage fireMsg(FIRE_EFFECT, V_LIGHT);
    
    void setup() {
    
      pinMode(RED_PIN, OUTPUT);
      pinMode(GREEN_PIN, OUTPUT);
      pinMode(BLUE_PIN, OUTPUT);
      pinMode(SERVO_H, OUTPUT);
      pinMode(SERVO_V, OUTPUT);
      gw.begin(incomingMessage, NODE_ID, NODE_REPEAT);
      gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      
      gw.present(SERVO_RGB, S_RGB_LIGHT, "Servo RGB", false);
      gw.present(SERVO_V, S_LIGHT, "Servo V", false);
      gw.present(SERVO_H, S_LIGHT, "Servo H", false);
      gw.request(SERVO_V, V_LIGHT);
      gw.request(SERVO_V, V_LIGHT);
      gw.request(SERVO_RGB, V_RGB);
    }
    
    void loop() {
      gw.process();
    
    }
    
    
    void incomingMessage(const MyMessage &message) {
    
      if (message.type == V_RGB) {
    
        String hexstring = message.getString();
        long number = (long) strtol( &hexstring[0], NULL, 16);
        RGB_values[0] = number >> 16;
        RGB_values[1] = number >> 8 & 0xFF;
        RGB_values[2] = number & 0xFF;
      }
      if (message.type == V_DIMMER) {
    
        if (message.sensor == SERVO_V) {
          myservo_v.attach(SERVO_V);
          myservo_v.write(map(message.getInt(), 0, 100, 72, 180));
          gw.wait(1000);
          myservo_v.detach();
        }
        if (message.sensor == SERVO_H) {
          myservo_h.attach(SERVO_H);
          myservo_h.write(map(message.getInt(), 0, 100, 0, 180));
          gw.wait(1000);
          myservo_h.detach();
        }
        if (message.sensor == SERVO_RGB) {
          dimmer = message.getInt();
          analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
          analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
          analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
        }
      }
    
      if (message.type == V_LIGHT) {
        if (message.sensor == SERVO_RGB) {
          if (message.getInt() == 0) {
            digitalWrite(RED_PIN, 0);
            digitalWrite(GREEN_PIN, 0);
            digitalWrite(BLUE_PIN, 0);
          }
          if (message.getInt() == 1) {
            analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
            analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
            analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
          }
        }
        if (message.sensor == SERVO_H) {
          if (message.getInt() == 0) {
            myservo_h.attach(SERVO_H);
            myservo_h.write(0);
            gw.wait(1000);
            myservo_h.detach();
          }
          if (message.getInt() == 1) {
            myservo_v.attach(SERVO_V);
            myservo_v.write(180);
            gw.wait(1000);
            myservo_v.detach();
          }
        }
        if (message.sensor == SERVO_H) {
          if (message.getInt() == 0) {
            myservo_h.attach(SERVO_H);
            myservo_h.write(0);
            gw.wait(1000);
            myservo_h.detach();
          }
          if (message.getInt() == 1) {
            myservo_v.attach(SERVO_V);
            myservo_v.write(180);
            gw.wait(1000);
            myservo_v.detach();
          }
        }
      }
    }
    
    
    1 Reply Last reply
    3
    • D Offline
      D Offline
      drock1985
      wrote on last edited by
      #2

      Hi,

      Very nice looking project. Do you have a list of the hardware you used and a schematic by any chance?

      My Projects
      2 Door Chime Sensor
      Washing Machine Monitor

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      22

      Online

      11.7k

      Users

      11.2k

      Topics

      113.1k

      Posts


      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • MySensors
      • OpenHardware.io
      • Categories
      • Recent
      • Tags
      • Popular